diff --git a/src/core_ffi/go_ffi/demo.c b/src/core_ffi/go_ffi/demo.c new file mode 100644 index 0000000..1964cae --- /dev/null +++ b/src/core_ffi/go_ffi/demo.c @@ -0,0 +1,7 @@ +#include "demo.h" + +#include + +void hello() { + printf("hello from c\n"); +} diff --git a/src/core_ffi/go_ffi/demo.cc b/src/core_ffi/go_ffi/demo.cc new file mode 100644 index 0000000..228e362 --- /dev/null +++ b/src/core_ffi/go_ffi/demo.cc @@ -0,0 +1,7 @@ +#include "demo.h" + +#include + +void hello() { + std::cout << "hello from c++" << std::endl; +} diff --git a/src/core_ffi/go_ffi/demo.h b/src/core_ffi/go_ffi/demo.h new file mode 100644 index 0000000..a5889f0 --- /dev/null +++ b/src/core_ffi/go_ffi/demo.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void hello(); + +#ifdef __cplusplus +} +#endif diff --git a/src/core_ffi/go_ffi/klotski.go b/src/core_ffi/go_ffi/klotski.go new file mode 100644 index 0000000..033b78d --- /dev/null +++ b/src/core_ffi/go_ffi/klotski.go @@ -0,0 +1,13 @@ +package main + +/* +#cgo LDFLAGS: -L${SRCDIR}/ -ldemo -lstdc++ +#include "demo.h" +*/ +import "C" +import "fmt" + +func main() { + fmt.Println("hello from go") + C.hello() +} diff --git a/src/core_ffi/go_ffi/test_c.sh b/src/core_ffi/go_ffi/test_c.sh new file mode 100755 index 0000000..4cb3030 --- /dev/null +++ b/src/core_ffi/go_ffi/test_c.sh @@ -0,0 +1,7 @@ +gcc -O3 -c demo.c -o demo.o +ar rcs libdemo.a demo.o +rm -f demo.o +ranlib libdemo.a + +go run klotski.go +rm -f libdemo.a diff --git a/src/core_ffi/go_ffi/test_cpp.sh b/src/core_ffi/go_ffi/test_cpp.sh new file mode 100755 index 0000000..822a912 --- /dev/null +++ b/src/core_ffi/go_ffi/test_cpp.sh @@ -0,0 +1,7 @@ +g++ -O3 -c demo.cc -o demo.o +ar rcs libdemo.a demo.o +rm -f demo.o +ranlib libdemo.a + +go run klotski.go +rm -f libdemo.a