Hey Marvin, Were you able to find any solutions to your problem? I have a similar problem of LDFLAGS not bubbling up through packages -- Here I have pkg A statically links libA pkg B (which imports A) also uses libA.
I get a linker error stating multiple definitions of the functions. -Sriram On Friday, November 7, 2014 at 1:46:31 AM UTC+5:30, Marvin Humphrey wrote: > > Greetings, > > I'd like to use CGO to access C functionality linked statically into a > *different* Go package. > > Here's a simplified demo: > > src/foo/foo.go: > > package foo > // int > // forty_two() { > // return 42; > // } > import "C" > > try.go: > > package main > import "fmt" > import "foo" > // extern int forty_two(); > // int > // forty_three() { > // return forty_two() + 1; > // } > import "C" > func main() { > fmt.Println(int(C.forty_three())) > } > > Here's the output when I try to run `try.go` (after running `go install > foo`): > > $ go run try.go > # command-line-arguments > Undefined symbols for architecture x86_64: > "_forty_two", referenced from: > __cgo_45ed811e7bcb_Cfunc_forty_two in try.cgo2.o > (maybe you meant: __cgo_45ed811e7bcb_Cfunc_forty_two) > ld: symbol(s) not found for architecture x86_64 > clang: error: linker command failed with exit code 1 (use > -v to see invocation) > > Examining the contents of the installed package file, it looks like > `_forty_two` ought to be available: > > $ nm -g pkg/darwin_amd64/foo.a > > pkg/darwin_amd64/foo.a(_all.o): > 0000000000000000 T _forty_two > > Suggestions? > > Using CGO_LDFLAGS to supply a full path to the package archive file didn't > do the trick. (Not that I expected it to, but the output is interesting.) > > $ export CGO_LDFLAGS=$GOPATH/pkg/darwin_amd64/foo.a > $ go run try.go > # command-line-arguments > ld: warning: ignoring file ./pkg/darwin_amd64/foo.a, file was built > for archive which is not the architecture being linked > (x86_64): ./pkg/darwin_amd64/foo.a > [...] > > Marvin Humphrey > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.