我正在用Ubuntu 16.04在Odroid上构建caffe,但我得到了一个链接错误:
[ 77%] Linking CXX executable compute_image_mean
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)':
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x28): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `std::string* google::MakeCheckOpString<unsigned int, int>(unsigned int const&, int const&, char const*)':
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringIjiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIjiEEPSsRKT_RKT0_PKc]+0x28): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `main':
compute_image_mean.cpp:(.text.startup+0xe6): undefined reference to `google::SetUsageMessage(std::string const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `cv::imread(std::string const&, int)'
../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
../lib/libcaffe.so.1.0.0: undefined reference to `cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::Status::ToString() const'
collect2: error: ld returned 1 exit status
tools/CMakeFiles/compute_image_mean.dir/build.make:130: recipe for target 'tools/compute_image_mean' failed
make[2]: *** [tools/compute_image_mean] Error 1
CMakeFiles/Makefile2:467: recipe for target 'tools/CMakeFiles/compute_image_mean.dir/all' failed
make[1]: *** [tools/CMakeFiles/compute_image_mean.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
字符串
下面是sudo ld lib/libcaffe.so.1.0.0
的输出:
sudo ld lib/libcaffe.so.1.0.0
ld: warning: cannot find entry symbol _start; defaulting to 000101ec
lib/libcaffe.so.1.0.0: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
lib/libcaffe.so.1.0.0: undefined reference to `cv::imread(std::string const&, int)'
lib/libcaffe.so.1.0.0: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
lib/libcaffe.so.1.0.0: undefined reference to `cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
lib/libcaffe.so.1.0.0: undefined reference to `leveldb::Status::ToString() const'
型
根据ldd lib/libcaffe.so.1.0.0
,所有需要的库都已找到。如何识别问题?
1条答案
按热度按时间flvlnr441#
这是一个老问题了,但当我在寻找自己的解决方案时偶然发现了它,我想我应该提到我的发现。
字符串
几乎可以肯定是因为你没有给给予
ld
任何C运行时的对象文件。我是在ARM(Raspberry Pi Zero,32位Linux)上构建的,所以我的ld
副本至少需要以下链接:型
另外值得注意的是,您可能不需要使用
sudo
运行链接器,因为链接程序没有任何特权,并且以超级用户身份运行所产生的权限可能会给您带来问题。顺便说一句,如果你很好奇,你可以通过使用
objdump
检查你的目标文件来找出_start
的真正位置。型
在我的例子中,
_start
完全丢失了,这是我需要意识到我丢失了C运行时部分的线索,因为_start
是在main
被调用之前执行的C运行时过程。