duanpeng1532 2012-04-30 01:02
浏览 29
已采纳

难道不是“去获取”只是获取文件,然后cgo +“去构建”它们吗? 显然不是

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:\Usersoxor\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?

  • 写回答

1条回答 默认 最新

  • dqn8235 2012-05-12 10:45
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?