我知道您在想什么-这已经回答了一百万遍了。我希望我可以在标题中添加一些内容,以便明确表明我已经知道库的顺序很重要。

我在Centos 6 64上使用g++。我有一个简单的测试程序:

#include <ptlib.h>

int main()
{
  PTimer indirectTimer1_;
  indirectTimer1_.SetNotifier(0);

  return 0;
}

然后编译并使用以下命令将其链接:
g++ -I./ptlib/include/ mm.cpp ptlib/lib_linux_x86_64/libpt_s.a -lpthread -lrt

我得到这个作为答案:
/tmp/cc53itXb.o: In function `main':
mm.cpp:(.text+0x52): undefined reference to `PTimer::SetNotifier(PNotifierTemplate<int> const&)'
collect2: ld returned 1 exit status

但我知道PTimer::SetNotifier在.a文件中:
nm -AC ptlib/lib_linux_x86_64/libpt_s.a | grep SetNotifier
ptlib/lib_linux_x86_64/libpt_s.a:osutil.o:0000000000003dd8 T PTimer::SetNotifier(PNotifierTemplate<long> const&)

更令人困惑的是,当我在32位的Centos 5上编译该库并运行相同的测试时,它的链接就很好了。

我尝试使用'-Lptlib / lib_linux_x86_64 -lpt_s',并且尝试使用-Wl,-start-group / -Wl,-end-group args无济于事。如果我在g++行中添加“ptlib / src / ptlib / unix / osutil.cxx”,它会进行编译和链接。不幸的是,这只是我们主程序中未引用函数的示例。并非所有的方法都是不确定的,像这样的一些看似随机的方法是未定义的(在Centos 5、32位上也可以很好地链接)。

如您所见,我已经尝试了很多东西,但仍然没有弄清楚。我还需要其他尝试!或有人指出我做错了一件非常容易的事。

最佳答案

undefined reference to `PTimer::SetNotifier(PNotifierTemplate<int> const&)'

                        PTimer::SetNotifier(PNotifierTemplate<long> const&)

注意intlong的区别吗?

关于c++ - 在静态库中找到对成员函数的 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19054857/

10-12 22:26
查看更多