【发布时间】:2013-08-05 03:21:15
【问题描述】:
我有一个可以编译的静态库,看起来(简化)如下:
math_util.h:
void foo(...);
math_util.cpp:
void foo(...) { ... }
A.cpp:
#include "math_util.h"
class A
{
bar() {
foo(...);
}
}
静态库编译良好。
但是,当我想在实际应用中使用 A 时,我得到:
undefined reference to `foo(...)'
但是当我用 nm 检查我的静态库时:
math_util.o:
U _GLOBAL_OFFSET_TABLE_
000000000000010a T _ZN8fooEPA2_dPdj
这不是原型问题,因为如果我将foo 的代码复制到 A.cpp 中,它可以正常工作。
所以,我不明白,为什么 G++ 找不到该符号,即使它显然存在于静态库中? 对于其他任何功能,我都没有这个问题。
注意:如果我正在运行 Linux,使用 QtCreator 并且我对两个项目都使用 qmake(但静态库是纯 STL C++,不涉及 Qt)。
编辑:查看真实的相关文件:
https://github.com/jcelerier/spectral-subtraction/blob/master/libnoisered/math_util.h
https://github.com/jcelerier/spectral-subtraction/blob/master/libnoisered/math_util.cpp
A.cpp:
项目文件:
https://github.com/jcelerier/spectral-subtraction/blob/master/libnoisered/libnoisered.pro
【问题讨论】:
-
显示更多源代码,并给出实际的编译过程(或
Makefile)。 -
我使用 qmake,它会依次生成 makefile。您只需在 project.pro 文件中指定
SOURCES = (cpp files)和HEADERS = (header files)即可,它会处理它,有点像 CMake