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

cmd/compile: document whether c-archive is supported on 386 #12048

Closed
sinuos-zz opened this issue Aug 6, 2015 · 9 comments
Closed

cmd/compile: document whether c-archive is supported on 386 #12048

sinuos-zz opened this issue Aug 6, 2015 · 9 comments

Comments

@sinuos-zz
Copy link

i use "GOARCH=386 go build -buildmode=c-archive",it shows ": no buildable Go source files in"
if use "GOARCH=386 go build -buildmode=c-shared", it shows "-buildmode=c-shared not supported on linux/386"

@bradfitz
Copy link
Contributor

bradfitz commented Aug 6, 2015

The error message seems to answer the question?

@bradfitz bradfitz closed this as completed Aug 6, 2015
@sinuos-zz
Copy link
Author

the error message shows "-buildmode=c-shared" not supported on linux/386, but "-buildmode=c-archive"
also not support on linux/386?

@bradfitz
Copy link
Contributor

bradfitz commented Aug 6, 2015

Over to @ianlancetaylor to clarify and/or fix the error message.

@bradfitz bradfitz reopened this Aug 6, 2015
@bradfitz bradfitz added this to the Go1.6 milestone Aug 6, 2015
@bradfitz bradfitz changed the title -buildmode=c-archive or -buildmode=c-shared not support 32 bit? cmd/compile: document whether c-archive is supported on 386 Aug 6, 2015
@ianlancetaylor
Copy link
Contributor

You need to tell us more. What files are in the directory in which you run the command? Are there any buildable Go source files there?

@sinuos-zz
Copy link
Author

yes,there is Go sources file ,if i just use "go build -buildmode=c-archive" without "GOARCH=386",it can build an archive file that can be linked into a C program,my Go version is go1.5rc1

@ianlancetaylor
Copy link
Contributor

I can not recreate the problem. Can you show a small example with the exact .go files you are using?

I do see a completely different problems. When setting GOARCH with -buildmode=c-archive, you may need to add a go build argument
-ldflags=-linkmode=external

@sinuos-zz
Copy link
Author

go

this is mytest.go
package main // import "mytest"

import _ "mytest/p"

func main() {} // ignored

this is p.go
package p //import "mytest/p"

import "C"

//export Foo
func Foo() int32 { return 42 }

use "GOARCH=386 go build -ldflags=-linkmode=external -buildmode=c-archive" failed

@ianlancetaylor
Copy link
Contributor

Ah. By default, cross-compilers do not enable cgo, so the go tool is ignoring p/p.go since it needs cgo. You need to say

CGO_ENABLED=1 GOARCH=386 go build -buildmode=c-archive

@sinuos-zz
Copy link
Author

oh,thank you

@golang golang locked and limited conversation to collaborators Aug 8, 2016
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

4 participants