├── smth.h ├── smth.cpp ├── README.md └── main.go /smth.h: -------------------------------------------------------------------------------- 1 | #ifndef AC_SMTH_GO_H 2 | #define AC_SMTH_GO_H 3 | 4 | int testX(); 5 | 6 | #endif // AC_SMTH_GO_H 7 | -------------------------------------------------------------------------------- /smth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" int testX() { 4 | printf("Hello world from C++\n"); 5 | fflush (stdout); 6 | return 42; 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-static-link-example 2 | Example (for memory) build static golang example binary with static C++ library (*.go + (*.cpp -> *.a) -> static binary) 3 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | /* 8 | #cgo LDFLAGS: -L./ -lsmth 9 | #include "smth.h" 10 | */ 11 | import "C" 12 | 13 | func main() { 14 | fmt.Println(`before`) 15 | fmt.Println(C.testX()); 16 | fmt.Println(`after`) 17 | return 18 | } 19 | --------------------------------------------------------------------------------