【问题标题】:How can I verify linked libraries?如何验证链接库?
【发布时间】:2013-09-12 21:39:22
【问题描述】:

我很难让一组特定的驱动程序工作,称为libnifalcon

我很确定安装成功,但是当我尝试编译示例程序时出现错误:

mars@marslab:~/Documents/libnifalcon-1.0/examples/findfalcons$ g++ findfalcons.cpp 
/tmp/cc8TtfGn.o: In function `runFalconTest()':
findfalcons.cpp:(.text+0x6b): undefined reference to `libnifalcon::FalconDevice::FalconDevice()'
findfalcons.cpp:(.text+0xdd): undefined reference to `libnifalcon::FalconDevice::getDeviceCount(unsigned int&)'
findfalcons.cpp:(.text+0x1bd): undefined reference to `libnifalcon::FalconDevice::open(unsigned int)'
findfalcons.cpp:(.text+0x224): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x2ac): undefined reference to `libnifalcon::FalconFirmware::loadFirmware(bool, unsigned int const&, unsigned char*)'
findfalcons.cpp:(.text+0x33b): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x3dd): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x504): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x512): undefined reference to `libnifalcon::FalconDevice::close()'
findfalcons.cpp:(.text+0x52b): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
findfalcons.cpp:(.text+0x53f): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
/tmp/cc8TtfGn.o: In function `void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()':
findfalcons.cpp:(.text._ZN11libnifalcon12FalconDevice17setFalconFirmwareINS_23FalconFirmwareNovintSDKEEEvv[void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()]+0x1d): undefined reference to `libnifalcon::FalconFirmwareNovintSDK::FalconFirmwareNovintSDK()'
collect2: ld returned 1 exit status

如何验证库是否正确链接?如果不是,我该怎么办?

【问题讨论】:

  • 您正在调用未在该范围内定义的函数。你写代码了吗?
  • 不,我正在尝试运行示例程序。我已经验证了命名空间存在(在一个单独的文件中)并且在其中声明了函数
  • 现在我明白了,开箱即用。你从哪里得到源代码?
  • @koodawg 你应该重写你的评论作为答案......

标签: c++ compiler-errors g++ shared-libraries


【解决方案1】:

你没有链接任何东西,即

g++ file.cpp

不链接到标准库以外的任何库。您需要链接其他模块或库,可能是 libnifalcon

g++ findfalcons.cpp -lnifalcon

或者...你可能需要做类似的事情

g++ -L/path/to/libnifalcon findfalcons.cpp -lnifalcon

where -I 告诉在哪里查找库。

【讨论】:

  • -I 用于头文件,您希望-L 设置库的搜索路径,或者只设置LIBRARY_PATH 环境变量(或LD_LIBRARY_PATH 用于动态库)。跨度>
  • 它仍然无法正常工作,但我认为我们越来越近了。当你写 -lnifalcon 而不是 -libnifalcon 时,我认为这是一个错字,但是 -lnifalcon 会编译并给我我总是得到的相同错误,但是 -libnifalcon 给我“/usr/bin/ld:找不到 -libnifalcon”错误。你是怎么知道使用 -lnifalcon 的?
  • 这是指定库的标准方法,您删除“lib” - 参见“man ld”。听起来您没有使用 -L 选项(或 Paul Griffiths 提到的 LD_LIBRARY_PATH)指定的 libnifalcon 的正确路径。
  • 我找到了正确的路径,-lnifalcon 不会返回错误(就像我的路径错误时那样),但我仍然得到未定义的引用。我应该在 libnifalcon.a 中查看它们是否存在吗?
  • 正确!此外,请确保您的可执行文件具有您想要的库,即“ldd 程序”向您显示链接到程序的所有库。 (osx 上的 otool)。然后,我会做类似'nm prog | grep symbol' 来检查你正在寻找的未定义的二进制文件。
猜你喜欢
  • 2014-09-08
  • 2019-09-04
  • 2012-09-21
  • 2021-12-04
  • 2019-01-28
  • 1970-01-01
  • 2023-03-20
  • 2023-02-01
  • 2011-12-27
相关资源
最近更新 更多