-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/cgo: wrong value of exported variables in a DLL #4339
Comments
Tried to build as per your instructions, and it does not build: C:\go\path\src\dllvar>BuildAll.bat C:\go\path\src\dllvar>gcc -c adll.c -DEXPORT_DLL C:\go\path\src\dllvar>gcc -shared -o adll.dll adll.o -Wl,--export-all-symbols C:\go\path\src\dllvar>go build goapp.go # command-line-arguments goapp.go:21[C:\DOCUME~1\aa\LOCALS~1\Temp\go-build288956491\command-line-arguments\_obj\goapp.cgo1.go:21]: cannot use &(*_Cvar_exported_var) (type *_Ctype_struct___0) as type *_Ctype_T in function argument My go version is: hg id a9b2f3280559 What I see is different. Would you like to tell me how I can reproduce your error? On the other hand, you have come up with solution to your problem. I would just use that if I could. Thank you. Alex Status changed to WaitingForReply. |
I guess the compilation error you've encountered is due to different Go or gcc version (and it might be another bug or misconfiguration), my env information is: Windows 7 64 bit Go version is 1.0.3 (64bit). MinGW-w64, gcc 4.7.1 with C compiler only (installed with TDM-GCC web installer http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm-gcc-webdl.exe/download). No C++ compiler is installed. The error occurs at this line (goapp.go): C.foo(&C.exported_var) I think by just commenting out this line, the line above it is able to illustrate this issue too: fmt.Println(C.exported_var, C.GoString(C.exported_var.name)) // C.foo(&C.exported_var) Because fmt.Println(C.exported_var, C.GoString(C.exported_var.name)) will fail to print any values. |
I can't reproduce this using ordinary "everything linked together" C. So it looks like it has something to do with the DLL. I will submit CL 13653043 which adds a test of the non-DLL case. I don't know what's wrong in the DLL case, though. I don't believe this will make it into Go 1.2. Labels changed: added go1.3maybe, removed go1.2maybe. |
This issue was updated by revision 71ed6eb. R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/13653043 |
I think this is fixed in the current development branch. I was encountering this bug on Windows XP with Go 1.4.2 and my own DLL, but I built the master branch of Go today and I'm no longer getting the error. My build environment may be slightly different than the official Go build machines, so it's probably advisable to retest it yourself. |
It's very likely fixed by #4069.
@alexbrainman, we might want a test for this in misc/cgo/testso.
|
This is now works (most likely fixed by #4069). Here https://go-review.googlesource.com/8523 is the test for it. Alex |
Update #4339. Change-Id: Ic1a7535562b8b824ba166777725f7ba5b9623d77 Reviewed-on: https://go-review.googlesource.com/8523 Run-TryBot: Minux Ma <minux@golang.org> Reviewed-by: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
https://go-review.googlesource.com/8523 was reverted. |
https://go-review.googlesource.com/#/c/8523/ contained test for issue #4339, not the fix. Issue #4339 was fixed by a series of CLs that fix issue #4069. We also have issue #10360 to keep track of progress fixing broken test https://go-review.googlesource.com/#/c/8523/ on darwin and netbsd. So I think this issue is resolved. Alex |
by hwang.dev:
Attachments:
The text was updated successfully, but these errors were encountered: