英文:
Go + Swig building with external lib
问题
我正在尝试使用OpenCV函数构建一个cpp文件。
Go 1.3表示,swig构建现在已经包含在go build工具中,但我没有找到一种告诉构建工具使用pkg-config添加包含目录和库参数的方法。
go test -x cv_test.go
cd /Users/pierre/Projects/go-swig
clang++ -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -g -O2 -o $WORK/_/Users/pierre/Projects/go-swig/_obj/binding.cpp.o -c ./binding.cpp
# _/Users/pierre/Projects/go-swig
在文件 ./binding.cpp 中包含的文件:
./binding.h:5:10: 致命错误: 'cv.h' 文件未找到
$WORK/command-line-arguments/_test/tiler.test
FAIL command-line-arguments [构建失败]
有人成功做到了吗?
英文:
I'm trying to build a cpp file with opencv functions.
Go 1.3 states that swig building is now bundled in go build tool but I didn't find a way to tell that build tool to add include dirs and libs args with pkg-config.
go test -x cv_test.go
cd /Users/pierre/Projects/go-swig
clang++ -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -g -O2 -o $WORK/_/Users/pierre/Projects/go-swig/_obj/binding.cpp.o -c ./binding.cpp
# _/Users/pierre/Projects/go-swig
In file included from ./binding.cpp:1:
./binding.h:5:10: fatal error: 'cv.h' file not found
$WORK/command-line-arguments/_test/tiler.test
FAIL command-line-arguments [build failed]
Has anyone did it successfully ?
答案1
得分: 6
截至目前,如果你使用pkg-config,Go无法正确地将包含路径传递给swig。我提交了一个补丁,但很可能要等到1.4版本发布才会包含在内。
因此,你可以选择使用带有补丁的Go构建,或者像@JamesHenstridge建议的那样手动指定路径,使用#cgo CXXFLAGS / #cgo LDFLAGS
。
英文:
As of right now, Go doesn't correctly pass include paths to swig if you use pkg-config, I submitted a patch but it most likely won't be included until 1.4 is out.
So you either build Go with the patch or manually specify the paths with #cgo CXXFLAGS / #cgo LDFLAGS
like @JamesHenstridge suggested.
答案2
得分: 4
你可以使用以下语法告诉CGo使用特定的pkg-config库的包含和链接标志,在你的Go源文件中的注释块中添加以下内容:
// #cgo pkg-config: some-package
import "C"
也就是说,将其与cgo处理的注释块中的其他声明一起包含在内。只需要在包中的一个.go
文件中包含这个注释块即可。你还可以指定额外的编译和链接标志:
// #cgo CXXFLAGS: -std=c++11
// #cgo LDFLAGS: -L/some/library/dir -lfoo
详细信息可以在cgo文档中找到。
英文:
You can tell CGo to use the include and link flags for a particular pkg-config library using the following syntax in one of your Go source files:
// #cgo pkg-config: some-package
import "C"
That is, include it along with any other declarations in the comment block processed by cgo. It is only necessary to include this in one of the .go
files in the package. You can also specify additional compile and link flags:
// #cgo CXXFLAGS: -std=c++11
// #cgo LDFLAGS: -L/some/library/dir -lfoo
Full details can be found in the cgo documentation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论