英文:
Using makefile with cgo
问题
我正在使用gcc在Windows上编译一个启用CGO的Go程序。gcc已经预编译到了Webots中。
我可以成功地使用以下makefile编译C程序:
### 不要修改:这包括了Webots全局Makefile.include
null :=
space := $(null) $(null)
WEBOTS_HOME_PATH?=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
gobuild:
go build -x -v
但是,如果我运行make gobuild
,它会失败并显示错误:fatal error: webots/robot.h: No such file or directory
在使用make gobuild
进行CGO构建时,无法找到头文件webots/robot.h
,但是在使用make
构建时可以找到。
我该如何解决这个问题?
英文:
I am compiling a CGO-enabled Go program using gcc in windows. The gcc comes precompiled into webots.
I can compile successfully the c program alone using the following makefile:
### Do not modify: this includes Webots global Makefile.include
null :=
space := $(null) $(null)
WEBOTS_HOME_PATH?=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
gobuild:
go build -x -v
But if I run make gobuild
it fails with the error: fatal error: webots/robot.h: No such file or directory
The header file webots/robot.h
cannnot be located when building with/for cgo using make gobuild
, but it is found when building with make
.
How do I fix this?
答案1
得分: 1
将包含webots/robot.h文件的目录添加到使用make gobuild构建时的包含路径中。您可以通过在makefile中的go build命令后添加-I标志,然后跟随包含头文件的目录的路径来实现此目的。例如:
gobuild:
go build -x -v -I/path/to/webots/include
英文:
Add the directory containing the webots/robot.h file to the include path when building with make gobuild. You can do this by adding the -I flag followed by the path to the directory containing the header file to the go build command in your makefile. For example:
gobuild:
go build -x -v -I/path/to/webots/include
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论