質問

I have a problem building a fairly simple local CGO project. Consider this very small CGO package of just 3 files (glut.go, support.c and support.h file) -- if I just go get it, these files are downloaded to

C:\Go\src\pkg\github.com\zombiezen\Go-GLUT\glut

then some secret magic happens and go get builds the following output file:

C:\Go\pkg\windows_amd64\github.com\zombiezen\Go-GLUT\glut.a

However, if I copy the three source files to \mytmp, cd into \mytmp and go build -o glut.a glut.go, I get some 40-60 error messages like this one:

C:\Users\roxor\AppData\Local\Temp\go-build191975110\command-line-arguments\_obj\glut.cgo2.o: In function `_cgo_b46885fb7c57_Cfunc_goCreateMenu':
./glut.go:195: undefined reference to `goCreateMenu'

If I run go get with the -x command-line argument, I can see that support.c is picked up during the build process and given to gcc:

gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\support.o -c .\support.c

However, with go build -x, this is not the case, support.c is skipped. Why? How do I call go build to work exactly like go get does?

役に立ちましたか?

解決

Just doing go build instead of go build somefile.go does it. So obvious now …

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top