【问题标题】:G++: linker doesnt seem to link correctlyG++:链接器似乎没有正确链接
【发布时间】:2013-01-31 23:03:41
【问题描述】:

我尝试编译一个我必须控制 DAQ 设备的程序。在 Windows 中,g++ 编译和链接正常,但在 Linux 中却不行。链接器(由 G++ 调用)显示:

g++ -Wall -o "acelerar-30-0" "acelerar-30-0.cpp" (en el directorio: /home/poly/)
/tmp/ccRLpB4q.o: In function `main':
acelerar-30-0.cpp:(.text+0x429): undefined reference to `AdxInstantAoCtrlCreate'
collect2: ld returned 1 exit status
Ha fallado la compilación.

cpp文件是这样的(剪切):

include stdlib.h
include stdio.h
include math.h
include "compatibility.h"
include "bdaqctrl.h"
include "comunes.h"
using namespace Automation::BDaq;
define deviceDescription L"USB-4704,BID#0"
int32       channelStart = 0;
int32       channelCount = 1;
double      voltaje[0];
int32       modo;
int32       ms;
int main(int argc, char* argv[])
{
    if (argc!=3)
        salidaerror(argv[0],1);
    channelStart = atoi(argv[1]);
    ms = atoi(argv[2]);
    if (channelStart<0||channelStart>1||ms<10)
        salidaerror(argv[0],1);
    ErrorCode ret = Success;
    InstantAoCtrl * instantAoCtrl = AdxInstantAoCtrlCreate();
...

我已经为此研究了几个小时,但找不到答案。该 SDK 适用于 Debian/Ubuntu,在 Linux 和 Windows 上具有相同的代码。

有什么提示吗?谢谢

编辑:由于格式不正确,删除了一些标记

【问题讨论】:

  • AdxInstantAoCtrlCreate() 定义在哪里?
  • 在文件 bdaqctrl.h 中。该文件有: InstantAoCtrl* AdxInstantAoCtrlCreate();和: __inline InstantAoCtrl* AdxInstantAoCtrlCreate() { return (InstantAoCtrl*)BDaqObjectCreate("AdxInstantAoCtrlCreate"); } 如果有很多事情......我可以上传文件,如果你愿意
  • 你可能应该发布相关的部分,是的......
  • pastebin.com/e1wZu1Em 那是 bdaqctrl.h
  • 该标头声明函数,它没有定义它 - 你需要链接到定义它的库

标签: linux linker g++


【解决方案1】:

根据我的(有限的)经验,典型的 gcc 行为将要求您在命令行中指定包含该函数的库作为参数,如下所示:

-lsome_library

即使库在您的库路径中也是必需的(可以使用 -L 指定其他库路径)。找到包含该函数的适当库文件,并在上面的参数格式中使用其文件名减去扩展名和前导“lib”。

【讨论】:

  • 你说得对:我找到了图书馆,所以仍然无法链接。它在 /usr/lib 中,它被称为 libbiodaq.so ,所以我附在 g++ 参数的末尾: -llibbiodaq 没有成功:( 仍在寻找它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-16
  • 2019-09-18
  • 1970-01-01
  • 2013-11-06
  • 2016-12-29
相关资源
最近更新 更多