linux下lrt静态库,c – 链接cgo库中的第三方静态库

我有一个Go库,为COpenImageIO库提供绑定(OpenImageiGO).我一直很乐意通过标准动态链接到libOpenImageIO来构建我的绑定,但现在我正试图静态链接.我遇到了一个问题,无论我尝试哪种标志组合,外部链接器都会因大量“未定义的引用”错误而失败.我似乎记得在过去提到过这个问题,并说链接器看到符号的顺序存在问题.但我似乎无法再找到这些信息.

这是我最近的构建尝试的一个简短示例,试图将其与boost,OpenColorIO和OpenImageIO的静态构建相链接:

$export CGO_CPPFLAGS="\n-I/path/to/boost/include \n-I/path/to/OpenColorIO/include \n-I/path/to/OpenImageIO/include"

$export CGO_LDFLAGS="\n-L/path/to/boost/lib -lboost_thread_static -lboost_system_static \n-L/path/to/OpenColorIO/lib -lopencolorio \n-L/path/to/OpenImageIO/lib -lOpenImageIO"

$go build -v -x --ldflags '-extldflags "-static"' github.com/justinfx/openimageigo

...

CGO_LDFLAGS="/path/to/boost/lib/libboost_system_static.a" "/path/to/boost/lib/libboost_thread_static.a" "/path/to/OpenColorIO/lib/libopencolorio.a" "/path/to/OpenImageIO/lib/libOpenImageIO.a" "-lstdc++" /vol/apps/go/1.3.0/pkg/tool/linux_amd64/cgo -objdir $WORK/github.com/justinfx/openimageigo/_obj/ -- -I/path/to/boost/include -I/path/to/OpenColorIO/include -I/path/to/OpenImageIO/include -I./cpp -I $WORK/github.com/justinfx/openimageigo/_obj/ -I/path/to/boost/include -I/path/to/OpenColorIO/include -I/path/to/OpenImageIO/include color.go imagebuf.go imagebufalgo.go imagecache.go imageinput.go imageoutput.go imagespec.go oiio.go roi.go

...

/usr/bin/g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -I/path/to/boost/include -I/path/to/OpenColorIO/include -I/path/to/OpenImageIO/include -I./cpp -I $WORK/github.com/justinfx/openimageigo/_obj/ -g -O2 -o $WORK/github.com/justinfx/openimageigo/_obj/all.cpp.o -c ./all.cpp

/usr/bin/g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -o $WORK/github.com/justinfx/openimageigo/_obj/_cgo_.o $WORK/github.com/justinfx/openimageigo/_obj/_cgo_main.o $WORK/github.com/justinfx/openimageigo/_obj/_cgo_export.o $WORK/github.com/justinfx/openimageigo/_obj/color.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imagebuf.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imagebufalgo.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imagecache.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imageinput.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imageoutput.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/imagespec.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/oiio.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/roi.cgo2.o $WORK/github.com/justinfx/openimageigo/_obj/all.cpp.o /path/to/boost/lib/libboost_system_static.a /path/to/boost/lib/libboost_thread_static.a /path/to/OpenColorIO/lib/libopencolorio.a /path/to/OpenImageIO/lib/libOpenImageIO.a -lstdc++

这里有一些樱桃挑选的错误,因为它是一个非常长的输出:

/path/to/OpenImageIO/lib/libOpenImageIO.a(OpenImageIO_dist^src^libOpenImageIO^color_ocio.cpp.o): In function `ColorConfig':

/path/to/OpenImageIO/OpenImageIO_dist/src/libOpenImageIO/color_ocio.cpp:141: undefined reference to `OpenColorIO::v1::SetLoggingLevel(OpenColorIO::v1::LoggingLevel)'

...

/path/to/OpenImageIO/lib/libOpenImageIO.a(OpenImageIO_dist^src^libOpenImageIO^imagebufalgo_copy.cpp.o): In function `boost::shared_mutex::lock()':

/path/to/boost/include/boost/thread/pthread/shared_mutex.hpp:138: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'

OpenImageIO似乎无法找到OpenColorIO的引用.并且,OpenImageIO似乎无法找到提升的参考.看起来链接期间发生事情的顺序并不是OpenColorIO或OpenCmageIO可用的提升符号,所以我得到了一堆符号错误.

我希望我做一些简单而愚蠢的事情,可以在我的构建过程中纠正.但是与外部库的cgo静态链接似乎比默认的动态链接方法更复杂.

更新#1

@ james-henstridge给出的答案是正确的,除了最后一次打嗝之外,我几乎完全建成了.我正在获取OpenColorIO所需的yaml-cpp失败的引用,即使它看起来我的订单正确.

这是我最新的env,我已经完成了所有必须添加的显式静态库:

$export CGO_CPPFLAGS="-I/usr/local/include -I/usr/include"

$export CGO_LDFLAGS="\n-L/usr/local/lib \n-L/usr/lib \n-L/usr/lib/x86_64-linux-gnu \n-lOpenImageIO \n-lHalf -lIex -lfreetype -lIlmThread -lImath -lIlmImf -lIlmThread \n-lOpenColorIO \n-lyaml-cpp -ltinyxml \n-lboost_regex -lboost_filesystem -lboost_thread -lboost_system \n-ltiff -lgif -lpng -ljpeg -lz \n-lrt -ldl"

$go test -v -x --ldflags '-extldflags "-static"' github.com/justinfx/openimageigo

...

/home/justin/src/OpenColorIO/src/core/OCIOYaml.cpp:329: undefined reference to `YAML::Node::begin() const'

...

/home/justin/src/OpenColorIO/build/ext/dist/include/yaml-cpp/nodereadimpl.h:79: undefined reference to `YAML::Node::GetScalar(std::basic_string, std::allocator >&) const'

...

/usr/local/lib/libOpenColorIO.a(OCIOYaml.cpp.o): In function `_FindFromNodeAtIndex':

/home/justin/src/OpenColorIO/build/ext/dist/include/yaml-cpp/nodeutil.h:53: undefined reference to `YAML::Node::FindAtIndex(unsigned long) const'

collect2: ld returned 1 exit status

更新#2

没关系更新#1.它与OpenColorIO特别相关,而不是一般问题.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值