-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/ld: Link to a shared library fails on windows #5273
Labels
Milestone
Comments
Thanks for the info. Could you please try applying the patch at https://golang.org/cl/8715043 and see if your test case works? (If you have the hg codereview extension installed you can use "hg clpatch 8715043"). Thanks. Owner changed to @ianlancetaylor. |
Thanks for working on the issue. I applied the patch and the error message changed to: # _/C_/GoIssue_dll/GoEcho C:\go\pkg\tool\windows_386\8l.exe: internal fatal error. Full log (go build -x): WORK=C:\Users\Simon\AppData\Local\Temp\go-build843336003 mkdir -p $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ cd C:\GoIssue_dll\GoEcho C:\go\pkg\tool\windows_386\cgo.exe -objdir $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ - - -I. -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ main.go C:\go\pkg\tool\windows_386\8c.exe -F -V -w -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj \ -I C:\go\pkg\windows_386 -o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_defun.8 -D GOOS_windows -D GOARCH_386 $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_defun.c gcc -I . -g -O2 -m32 -mthreads -print-libgcc-file-name gcc -I . -g -O2 -m32 -mthreads -I. -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ -o $WO RK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_main.o -c $WORK\_\C_\GoIssue_dll\GoEcho\_ob j\_cgo_main.c gcc -I . -g -O2 -m32 -mthreads -I. -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ -o $WO RK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_export.o -c $WORK\_\C_\GoIssue_dll\GoEcho\_ obj\_cgo_export.c gcc -I . -g -O2 -m32 -mthreads -I. -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ -o $WO RK\_\C_\GoIssue_dll\GoEcho\_obj\main.cgo2.o -c $WORK\_\C_\GoIssue_dll\GoEcho\_ob j\main.cgo2.c gcc -I . -g -O2 -m32 -mthreads -o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_.o $WO RK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_main.o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_ cgo_export.o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\main.cgo2.o libecho_dll.a C:\go\pkg\tool\windows_386\cgo.exe -objdir $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ - dynimport $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_.o -dynout $WORK\_\C_\GoIssue_ dll\GoEcho\_obj\_cgo_import.c C:\go\pkg\tool\windows_386\8c.exe -F -V -w -I $WORK\_\C_\GoIssue_dll\GoEcho\_obj \ -I C:\go\pkg\windows_386 -o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_import.8 - D GOOS_windows -D GOARCH_386 $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_import.c gcc -I . -g -O2 -m32 -mthreads -o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_all.o $WOR K\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_export.o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\ main.cgo2.o libecho_dll.a -Wl,-r -nostdlib -lmingwex -lmingw32 c:/mingw/bin/../l ib/gcc/mingw32/4.7.2/libgcc.a C:\go\pkg\tool\windows_386\8g.exe -o $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_go_.8 - p _/C_/GoIssue_dll/GoEcho -D _/C_/GoIssue_dll/GoEcho -I $WORK $WORK\_\C_\GoIssue _dll\GoEcho\_obj\_cgo_gotypes.go $WORK\_\C_\GoIssue_dll\GoEcho\_obj\main.cgo1.go C:\go\pkg\tool\windows_386\pack.exe grcP $WORK $WORK\_\C_\GoIssue_dll\GoEcho.a $ WORK\_\C_\GoIssue_dll\GoEcho\_obj\_go_.8 $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo _import.8 $WORK\_\C_\GoIssue_dll\GoEcho\_obj\_cgo_defun.8 $WORK\_\C_\GoIssue_dll \GoEcho\_obj\_all.o cd . C:\go\pkg\tool\windows_386\8l.exe -o GoEcho.exe -L $WORK $WORK\_\C_\GoIssue_dll\ GoEcho.a # _/C_/GoIssue_dll/GoEcho C:\go\pkg\tool\windows_386\8l.exe: internal fatal error. |
the solution is simple: we don't need implib (*.a) created by gcc thanks to the new cgo build procedure. just change the LDFLAGS line to #cgo LDFLAGS: echo_dll.dll and main.go will build and run fine. @simonhege, please test this solution. i will add an example to misc/cgo/testdll make it run in run.bat. Status changed to WaitingForReply. |
note: we also need https://golang.org/cl/8715043/ for windows/amd64 (not needed for windows/386). |
@minux, it still fails here: C:\tmp\zzz\1.1\issue5273>build.bat C:\tmp\zzz\1.1\issue5273>cd GccEcho C:\tmp\zzz\1.1\issue5273\GccEcho>gcc -c Echo.c -DECHO_EXPORTS C:\tmp\zzz\1.1\issue5273\GccEcho>gcc -shared -o echo_dll.dll Echo.o -Wl,--out-im plib,libecho_dll.a Creating library file: libecho_dll.a C:\tmp\zzz\1.1\issue5273\GccEcho>gcc -c main.c C:\tmp\zzz\1.1\issue5273\GccEcho>gcc -o main_dll.exe main.o -L. -lecho_dll C:\tmp\zzz\1.1\issue5273\GccEcho>cd ..\GoEcho C:\tmp\zzz\1.1\issue5273\GoEcho>copy ..\GccEcho\Echo.h 1 file(s) copied. C:\tmp\zzz\1.1\issue5273\GoEcho>rem copy ..\GccEcho\libecho_dll.a C:\tmp\zzz\1.1\issue5273\GoEcho>copy ..\GccEcho\echo_dll.dll 1 file(s) copied. C:\tmp\zzz\1.1\issue5273\GoEcho>go build # _/C_/tmp/zzz/1.1/issue5273/GoEcho C:\DOCUME~1\brainman\LOCALS~1\Temp\go-build279830815\_\C_\tmp\zzz\1.1\issue5273\ GoEcho.a(_all.o): malformed pe file: unexpected flags -0x3fd00000 for PE section .idata$2 C:\tmp\zzz\1.1\issue5273\GoEcho> |
This issue was closed by revision 8c72b81. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Attachments:
The text was updated successfully, but these errors were encountered: