douweng7308 2014-08-27 08:13
浏览 108
已采纳

Go + Swig使用外部库构建

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 ?

  • 写回答

2条回答 默认 最新

  • dongwei3151 2014-08-27 11:41
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys