-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: explain when to use -ldflags=-extar when cross-compiling #45395
Comments
Can you show us the code that you are trying to build? |
Here's a simple example that has the same problem (at least for me). test.go:
test.c:
|
What happens if you use |
That worked. You are the man! Thank you. BTW: is there documentation that describes this necessary step, which I missed? In case it answers any other future questions/issues I might otherwise run into |
I'm going to reopen this to get better documentation. We should also consider supporting an |
There appears to already be an go/src/cmd/go/internal/envcmd/env.go Line 112 in 4c1a7ab
Looks like it might just be a few lines change to get go/src/cmd/link/internal/ld/lib.go Line 1218 in 972e883
|
What version of Go are you using (
go version
)?go version go1.16.3 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?darwin + amd64
What did you do?
I am compiling Go into a static archive to be called with C code. It works when I compile for the native platform. It does not work when I try to cross-compile for Windows using mingw64
Works:
cross-compile C for Win using mingw64 (no Go code) (to confirm that my C cross-compile toolchain works)
x86_64-w64-mingw32-gcc only_c.c -o only_c.exe
native compile: Go to static archive, exporting a function
myExportedFunction
, called by C executable:go build -buildmode=c-archive test.go
# ( exports myExportedFunction )clang test.c test.a -o test
# ( test.c calls myExportedFunction )No errors or warnings:
CC=x86_64-w64-mingw32-gcc GOOS=windows CGO_ENABLED=1 go build -o test.w64a -buildmode=c-archive test.go
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CPP=x86_64-w64-mingw32-cpp RANLIB=x86_64-w64-mingw32-ranlib AR=x86_64-w64-mingw32-ar LIBTOOL=/opt/mingw64/bin/libtool GOARCH=amd64 GOOS=windows CGO_ENABLED=1 go build -o test.w64a -buildmode=c-archive test.go
Fails:
x86_64-w64-mingw32-gcc test.c test.w64a -o test.exe
/.../x86_64-w64-mingw32-ld: /.../ccmb8owx.o:test.c:(.text+0x29): undefined reference to "myExportedFunction"
What did you expect to see?
No error message, and test.exe file created
What did you see instead?
Error message
The text was updated successfully, but these errors were encountered: