Skip to content

Commit ac5a2f3

Browse files
committed
Add good makefile example in clib folder.
1 parent 474d18d commit ac5a2f3

6 files changed

Lines changed: 42 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ examples/vgg/models/vgg16/*.npy
3131
new_sun.png
3232
new_sun*.png
3333
new_sun_hello.png
34-
test/correspondence/gh.out
34+
test/correspondence/gh.out
35+
!Makefile

CMakeLists.txt

Whitespace-only changes.

clib/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
all: myProgram
2+
3+
myProgram: test.chpl libmylib.a #libmylib.a is the dependency for the executable
4+
chpl mylib.h -L. -lmylib -o myProgram test.chpl
5+
6+
# gcc -lm -o myProgram main.o -L. -lmylib
7+
8+
mylib.o: mylib.c mylib.h
9+
gcc -O -c mylib.c mylib.h
10+
11+
libmylib.a: mylib.o
12+
ar rcs libmylib.a mylib.o
13+
14+
libs: libmylib.a
15+
16+
clean:
17+
rm -f myProgram *.o *.a *.gch #This way is cleaner than your clean

clib/mylib.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
#include "mylib.h"
3+
4+
int myfunction(int a) {
5+
return a + 1;
6+
}
7+
8+
9+

clib/mylib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
int myfunction(int a);
4+

clib/test.chpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// require "mylib.h", "mylib.c";
2+
3+
4+
extern proc myfunction(x: int): int;
5+
6+
7+
8+
writeln("Hello, world!");
9+
10+
writeln(myfunction(5));

0 commit comments

Comments
 (0)