Skip to content

Commit b44a8fc

Browse files
committed
make maincpp.o working in chapel-webcam.
1 parent 689344c commit b44a8fc

9 files changed

Lines changed: 116 additions & 6 deletions

File tree

demos/video/chapel-webcam/Makefile

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,64 @@
11

22
include lib/Makefile.smol
33

4-
all: libsmol.a main
4+
all: libsmol cppmain
55

6-
libsmol.a: smol.chpl
7-
chpl --library --library-makefile --library-cmakelists smol.chpl
6+
# chpl --library --library-makefile --library-cmakelists smol.chpl
87

9-
main: main.c libsmol.a
8+
libsmol: smol.chpl
9+
chpl \
10+
--library \
11+
--dynamic \
12+
--library-dir lib \
13+
--savec lib/savec \
14+
--library-makefile \
15+
--library-cmakelists \
16+
--no-munge-with-ids \
17+
smol.chpl
18+
19+
cmain: main.c
1020
$(CHPL_COMPILER) $(CHPL_CFLAGS) -o main main.c $(CHPL_LDFLAGS)
1121

22+
23+
24+
CPP_CFLAGS = \
25+
-Ilib \
26+
-Wno-unused \
27+
-Wno-uninitialized \
28+
-Wno-pointer-sign \
29+
-Wno-incompatible-pointer-types \
30+
-Wno-tautological-compare \
31+
-I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal \
32+
-I$(CHPL_RUNTIME_INCL)/localeModels/flat \
33+
-I$(CHPL_RUNTIME_INCL)/localeModels \
34+
-I$(CHPL_RUNTIME_INCL)/comm/none \
35+
-I$(CHPL_RUNTIME_INCL)/comm \
36+
-I$(CHPL_RUNTIME_INCL)/tasks/qthreads \
37+
-I$(CHPL_RUNTIME_INCL)/. \
38+
-I$(CHPL_RUNTIME_INCL)/./qio \
39+
-I$(CHPL_RUNTIME_INCL)/./atomics/cstdlib \
40+
-I$(CHPL_RUNTIME_INCL)/./mem/jemalloc \
41+
-I$(CHPL_THIRD_PARTY)/utf8-decoder \
42+
-I$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include \
43+
-Wno-error=unused-variable \
44+
-I$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/include \
45+
-I. -I/opt/homebrew/Cellar/gmp/6.3.0/include \
46+
-I/opt/homebrew/Cellar/hwloc/2.12.0/include \
47+
-I/opt/homebrew/Cellar/jemalloc/5.3.0/include \
48+
-I/opt/homebrew/include
49+
50+
CPP_LDFLAGS = -Llib -lsmol -L$(CHPL_RUNTIME_LIB)/darwin/llvm/arm64/cpu-native/loc-flat/comm-none/tasks-qthreads/tmr-generic/unwind-none/mem-jemalloc/atomics-cstdlib/hwloc-system/re2-bundled/fs-none/lib_pic-none/san-none -lchpl -L$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -Wl,-rpath,$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -lqthread -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -L$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lre2 -Wl,-rpath,$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lm -lpthread -L/opt/homebrew/Cellar/gmp/6.3.0/lib -lgmp -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -Wl,-rpath,/opt/homebrew/Cellar/hwloc/2.12.0/lib -lhwloc -L/opt/homebrew/Cellar/jemalloc/5.3.0/lib -Wl,-rpath,/opt/homebrew/Cellar/jemalloc/5.3.0/lib -ljemalloc -L/opt/homebrew/lib
51+
52+
# $(CHPL_LINKER) $(CHPL_CFLAGS) -o main main.cpp $(CHPL_LDFLAGS)
53+
54+
maincpp.o: main.cpp
55+
$(CHPL_COMPILER) $(CHPL_CFLAGS) -fPIC main.cpp -o maincpp.o $(CHPL_LDFLAGS)
56+
$(CHPL_COMPILER) $(CHPL_CFLAGS) -fPIC main.cpp -o maincpp $(CHPL_LDFLAGS)
57+
58+
maincpp: maincpp.o
59+
$(CHPL_LINKER) -o maincpp maincpp.o
60+
#$(CHPL_LINKER) $(CHPL_CFLAGS) -o main main.o $(CHPL_LDFLAGS)
61+
1262
clean:
13-
rm -f main lib/libsmol.a
63+
rm -f maincpp maincpp.o main.o
64+
# rm -f main lib/libsmol.a

demos/video/chapel-webcam/lib/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
849 KB
Binary file not shown.
1.02 MB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include "stdchpl.h"
22
#include "wctype.h"
33
#include "ctype.h"
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
49
void chpl__init_smol(int64_t _ln,
510
int32_t _fn);
611
int64_t square(int64_t x);
12+
int64_t sumArray(chpl_external_array * a);
13+
void printArray(chpl_external_array * a);
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif

demos/video/chapel-webcam/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ int main(int argc, char* argv[]) {
55

66
square(3);
77

8+
int64_t array[4] = {1,2,3,4};
9+
chpl_external_array array_ptr = chpl_make_external_array_ptr(&array,4);
10+
int64_t sum = sumArray(&array_ptr);
11+
chpl_free_external_array(array_ptr);
12+
printf("sum: %d\n", sum);
13+
14+
15+
int64_t matrix[2][3] = { {1, 4, 2}, {3, 6, 8} };
16+
chpl_external_array matrix_ptr = chpl_make_external_array_ptr(matrix, 3 * 2);
17+
printArray(&matrix_ptr);
18+
chpl_free_external_array(matrix_ptr);
19+
20+
821
chpl_library_finalize();
922

1023
return 0;

demos/video/chapel-webcam/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "lib/smol.h"
2+
3+
int main(int argc, char* argv[]) {
4+
chpl_library_init(argc, argv);
5+
6+
square(3);
7+
8+
int64_t array[4] = {1,2,3,4};
9+
chpl_external_array array_ptr = chpl_make_external_array_ptr(&array,4);
10+
int64_t sum = sumArray(&array_ptr);
11+
chpl_free_external_array(array_ptr);
12+
printf("sum: %d\n", sum);
13+
14+
15+
int64_t matrix[2][3] = { {1, 4, 2}, {3, 6, 8} };
16+
chpl_external_array matrix_ptr = chpl_make_external_array_ptr(matrix, 3 * 2);
17+
printArray(&matrix_ptr);
18+
chpl_free_external_array(matrix_ptr);
19+
20+
21+
chpl_library_finalize();
22+
return 0;
23+
}
24+
25+
33.3 KB
Binary file not shown.

demos/video/chapel-webcam/smol.chpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@ export proc square(x: int): int {
44
return x * x;
55
}
66

7+
export proc sumArray(a: [] int): int {
8+
var sum: int = 0;
9+
for x in a do
10+
sum += x;
11+
return sum;
12+
}
13+
14+
export proc printArray(a: [] int): void {
15+
writeln(a);
16+
}
17+

0 commit comments

Comments
 (0)