You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think cgo can handle C++ name mangling, and you need to export your C++ functions with an extern "C".
extern "C" void foo(int argc, char**argv) {
}
Note I also changed the name from main to foo. I have no idea what the go runtime/linker would try to call with your code, but could imagine it having real hard times resolving the symbol. I'll mark this as Closed, as I don't think there's an error here.
Thinking about it further, I'm going to reopen this. I think it might be valuable to fail earlier for the user. Your reasonable assumptions about what should happen should have failed in a more friendly manner.
This actually isn't due to C++ symbol name mangling. C++ doesn't mangle the name main.
The problem is that the Go runtime also provides a symbol main, which is used to start the program when using external linking, as happens when using cgo.
So the upshot is that you can't use a symbol named main in your library. Which is true of C or C++ libraries in general anyhow.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Put
main.cpp
,main.hpp
,main.go
,Makefile
in the same folder and runmake
.main.cpp
main.hpp
main.go
Makefile
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
As mentioned before
What did you expect to see?
It should return without error.
What did you see instead?
As mentioned before
The text was updated successfully, but these errors were encountered: