Skip to content
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

win7 64-bit platforms, cgo compiler error #6731

Closed
gopherbot opened this issue Nov 7, 2013 · 4 comments
Closed

win7 64-bit platforms, cgo compiler error #6731

gopherbot opened this issue Nov 7, 2013 · 4 comments
Milestone

Comments

@gopherbot
Copy link

by anwar.root:

This source code in the attachment, the purpose is to test the windows platform golang
cgo calls; Of course, in my project also used in this way calls

D:\win_amd64_cgo_test>gcc -O2 -c foo.c
D:\win_amd64_cgo_test>ar q libfoo.a foo.o
D:\win_amd64_cgo_test>go version
go version go1.2rc3 windows/amd64

D:\win_amd64_cgo_test>go build test.go   ---> By 'go build', with the name of the
program 'test.go' way of compiling
# command-line-arguments
x(0): not defined    ---> Produces undefined, but the program 'test.exe' has been
compiled out!

D:\win_amd64_cgo_test>test.exe   ---> To run it, but there is a serious error
output!
Invoking c library...
panic: invalid memory address or nil pointer dereference
fatal error: panic during malloc
[signal 0xc0000005 code=0x0 addr=0x50 pc=0x41d2aa]

runtime stack:
runtime.panic(0x4a8480, 0x5883f8)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist960365359/go/src/pkg/runtime/panic.c:233 +0x2c
runtime: unexpected return pc for _cgo_2c321763ad73_Cfunc_x called from 0x2

goroutine 1 [syscall]:
runtime.cgocall(0x47d6b7, 0x692eb8)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist960365359/go/src/pkg/runtime/cgocall.c:149 +0x120 fp=0x692ea0
main._Cfunc_x(0xa, 0x16)
        C:/Users/ADMINI~1/AppData/Local/Temp/go-build126955343/command-line-arguments/_obj/_cgo_defun.c:52 +0x34 fp=0x692eb8
main.main()
        D:/win_amd64_cgo_test/test.go:12 +0x59 fp=0x692f48
runtime.main()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist960365359/go/src/pkg/runtime/proc.c:220 +0x132 fp=0x692fa0
runtime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist960365359/go/src/pkg/runtime/proc.c:1394 fp=0x692fa8

goroutine 3 [syscall]:
runtime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist960365359/go/src/pkg/runtime/proc.c:1394





//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The same procedure, the following compilation mode

D:\win_amd64_cgo_test>go version
go version go1.2rc3 windows/amd64

D:\win_amd64_cgo_test>go build     ---> Direct hit go build; without a program
name, the compiler generated a directory name 'win_amd64_cgo_test.exe' program

D:\win_amd64_cgo_test>win_amd64_cgo_test.exe     ---> To run it, the result is ok
Invoking c library...
Hello World>>>>>>>
Done  13

D:\win_amd64_cgo_test>

Attachments:

  1. win_amd64_cgo_test_OK_version.rar (496000 bytes)
  2. win_amd64_cgo_test_error_version.rar (499007 bytes)
@gopherbot
Copy link
Author

Comment 1 by anwar.root:

from windows xp, 32bit,  test as following:
E:\win_amd64_cgo_test_OK_version>go build test.go
# command-line-arguments
C:\DOCUME~1\kovi\LOCALS~1\Temp\go-build030420267\command-line-arguments\_obj\tes
t.cgo2.o: In function `cgo_2c321763ad73_Cfunc_x':
E:/win_amd64_cgo_test_OK_version/test.go:37: undefined reference to `x'
collect2.exe: error: ld returned 1 exit status
E:\win_amd64_cgo_test_OK_version>go build
E:\win_amd64_cgo_test_OK_version>win_amd64_cgo_test_OK_version.exe
Invoking c library...
Hello World>>>>>>>
Done  13
E:\win_amd64_cgo_test_OK_version>

@gopherbot
Copy link
Author

Comment 2 by anwar.root:

Test.go
+++++++++++++++++++
package main
import "fmt"
// #cgo CFLAGS: -I.
// #cgo LDFLAGS: -L. -lfoo 
// #include "foo.h"
import "C"
func main() {
  fmt.Printf("Invoking c library...\n")
  fmt.Println("Done ", C.x(10) )
}
// gcc -O2 -c foo.c
// ar q libfoo.a foo.o

@ianlancetaylor
Copy link
Contributor

Comment 3:

I don't see a bug here.
"go build test.go" builds the single program test.go.  It doesn't do cgo support or
anything else.
"go build" builds the package in the directory in which you run the command.  It does
cgo support.
It seems that you are showing that "go build" works but "go build test.go" fails.  That
is expected.
Please reopen and explain if I have misunderstood.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

Comment 4 by anwar.root:

Thank you very much,
Before this; I have been on the Linux platform, the 64-bit compiler; compiled as with
the program name, such as: 'go build test.go', is ok; Now I'm in the windows platform is
compiled with a program compiled unsuccessful, so I thought it was a mistake!

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants