对静态库中找到的成员函数的未定义引用
Undefined reference to member function found in static library
我知道你在想什么 - 这已经被回答了一百万次。我希望我能在标题中加入一些东西,以清楚地表明我已经知道库的顺序很重要。
我在 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&)
更令人困惑的是,当我在 Centos 5、32 位上编译库并运行相同的测试时,它的链接很好。
我尝试使用'-Lptlib/lib_linux_x86_64 -lpt_s',我试过使用-wl,--start-group/-wl,--end-group args无济于事。如果我将'ptlib/src/ptlib/unix/osutil.cxx'添加到g++行,它可以很好地编译和链接。不幸的是,这只是我们主程序中未引用函数的一个示例。不是全部,只是像这样一些看似随机的方法没有定义(在 Centos 5,32 位上链接也很好(。
如您所见,我已经尝试了很多东西,但仍然没有弄清楚。我需要别的东西来尝试!或者有人指出我做错了一件非常容易的事情。
undefined reference to `PTimer::SetNotifier(PNotifierTemplate<int> const&)'
PTimer::SetNotifier(PNotifierTemplate<long> const&)
请注意int
与 long
?
相关文章:
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 将公共但非静态的成员函数与ALGLIB集成
- 使用指向成员的指针将成员函数作为参数传递
- 将重载的成员函数传递给函数模板
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 如何在C++中使用非静态成员函数作为回调函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 关联容器的下界复杂性:成员函数与非成员函数
- 在 C++ 中用派生类型重写成员函数
- 链表的泛型函数remove()与成员函数remove)
- 如何将lambda作为模板类的成员函数参数
- constexpr构造函数需要常量成员函数时出现问题
- 将自由函数绑定为类成员函数
- 区分非成员函数和头文件中的成员函数
- 如何从子成员函数修改父公共成员变量
- 保留对其他类的成员函数的引用
- 在运算符重载定义中使用成员函数(const错误)
- 内联如何影响模块接口中的成员函数
- 将成员函数指针作为参数传递给模板方法