I am using this:
// foo.h
#ifdef __cplusplus
extern "C" {
#endif
void foo();
#ifdef __cplusplus
}
#endif
//foo.cc
void foo() {
cout << "Hello World" << endl;
}
to link between my cgo process and c++ process. I want to access a golang function from my c++ function foo
. My go looks like:
// #include "foo.h"
import "C"
func golangPart() {
//do stuff in go
}
func main() {
C.foo()
}
I want to access golangPart()
from the c++. I have tried this:
//foo.h
void golangPart();
#ifdef __cplusplus
extern "C" {
#endif
void foo();
#ifdef __cplusplus
}
#endif
//foo.cc
void foo() {
golangPart();
}
But it gave me this error:
./foo.cc:42: undefined reference to `golangPart()'
collect2.exe: error: ld returned 1 exit status