针对C 库链接时的未定义参考
undefined reference in linking against C++ library
i编写一个C 库,在链接到库时,找不到其中的符号。这是我得到的:
A.CPP:
void zak()
{
}
test.cpp:
extern void zak();
int main(int argc, const char ** argv)
{
zak();
}
makefile:
all:
g++ -c -o a.o a.cpp
ar r libzak.a a.o
g++ -L. -lzak test.cpp -o test
这是我(Linux Mint 13)框上说的:
g++ -c -o a.o a.cpp
ar r libzak.a a.o
g++ -L. -lzak test.cpp -o test
/tmp/ccC4cnLV.o: In function `main':
test.cpp:(.text+0x7): undefined reference to `zak()'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
我敢肯定我缺少一些明显的东西,但是这是什么?
链接顺序很重要。将-lzak
放在test.cpp
之后的链接线上。
我认为-l适用于共享库(.so)。尝试以下操作:g libzak.a test.cpp -o test
相关文章:
- GTest EXPECT_EQ给出未定义的错误参考
- 在VSCode中编译C++给了我一个未定义的参考
- Armadillo正在为共享的lapack库获取未定义的参考
- 我对C++程序有一个未定义的参考,不知道如何处理它
- 使用Arduino IDE的构造函数的未定义参考错误
- 在C++中使用 CImg 的未定义参考错误
- gtest的未定义参考
- 未定义参考 cv::鱼眼::校准
- WEBRTC的未定义参考
- 如何编译ZBAR示例?(未定义参考..)
- 针对C 库链接时的未定义参考
- 命名空间外部变量的未定义参考/多重定义,C 结构问题
- 简单QT程序中的未定义参考
- 主要makefile中的未定义参考
- C 标题中的外部变量的未定义参考
- 对[class::function]的未定义引用/对[class]的typeinfo的未定义参考
- icu 54-未定义参考
- 信号上的QT未定义参考编译错误
- boost 1.58未定义参考
- QT未定义参考错误(Qextserialport)