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/go: 'go install' with cgo disabled does not report pure-cgo package #6078

Closed
shivakumargn opened this issue Aug 8, 2013 · 7 comments
Closed
Milestone

Comments

@shivakumargn
Copy link
Contributor

Building 386 binary on amd64 has CGO_ENABLED=0 as default.

I noticed two issues:
1. A cgolib.a file is getting generated under linux_386 even though CGO_ENABLED=0
2. Another package that requires cgolib.a fails to build with unhelpful error messages.
Error message needs to improve.

> go build hi.go
# command-line-arguments
./hi.go:4: imported and not used: "cglib"
./hi.go:9: undefined: cglib

On building with CGO_ENABLED=1, error vanishes.
@robpike
Copy link
Contributor

robpike commented Aug 12, 2013

Comment 1:

Labels changed: added priority-soon, cgo, removed priority-triage.

Status changed to Accepted.

@ianlancetaylor
Copy link
Contributor

Comment 3:

Please tell us the contents of hi.go.  Thanks.

@shivakumargn
Copy link
Contributor Author

Comment 4:

My current sources are with too many dependencies to share. Will try to construct a
small example.
Following are the conditions under which problem occurs:
1. hi.go uses another library mylib
2. The mylib library in turn links to a my own 32-bit C library
3. GOHOSTARCH is amd64
4. Install mylib with GOARCH=386 and CGO_ENABLED=1
5. If GOARCH is set to 386 (with default CGO_ENABLED value which is 0) -> happens if one
uses another shell or logins in after few days and unsuspectingly just sets GOARCH
Now trying to build hi.go gives errors as above.

@shivakumargn
Copy link
Contributor Author

Comment 5:

Additional hint - probably related issue:
Installing a cgo package when CGO_ENABLED=0, fails silently 
// mylib.go (in exp/cgoerr/mylib package)
package mylib
/*
#include <stdio.h>
#include <stdlib.h>
void myprint(char* s) {
    printf("%s", s);
}
*/
import "C"
import "unsafe"
func Funca() {
    cs := C.CString("Hello from stdio\n")
    C.myprint(cs)
    C.free(unsafe.Pointer(cs))
}
func Funcb() {
    fmt.Println("...in mylib Funcb()")
}
> cd $GOPATH/src/exp/cgoerr/mylib
> export CGO_ENABLED=0
> go install .               --> no error message inspite of failure
> ls $GOPATH/pkg/linux_386   --> no package is installed

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 6:

I see two bugs in your report.
1. Your program hi.go is importing "cglib" but that package has
declared some other name for itself (not cglib), which is why you
see both `imported and not used: "cglib"` and `undefined: cglib`
when you try to use it.
I fixed this yesterday. The first error will now say
    ./hi.go:4: imported and not used: "cglib" as pkgname
where pkgname is whatever cglib has declared itself to be.
2. If you are in a directory with only cgo files but cgo is disabled,
'go install .' fails to print an error (it does nothing).
I will make this bug about #2.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 7:

Labels changed: added go1.2, removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 8:

This issue was closed by revision 611b182.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 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

5 participants