将静态库链接到测试脚本时出错
我正在为一个小项目构建一个静态库,当我使用 ar 编译它时,它会正确链接。
当我去包含相关的头文件并将测试脚本链接到存档时;
LINK = -lpthread -lcryptopp -L./path/to/archive/ -luttu
r: ../inc/uttu.hpp
g++ -std=c++20 rnet.cpp -o r.out $(LINK)
我收到链接器错误;
/usr/bin/ld: /tmp/cc7h6RHu.o: in function `main':
rnet.cpp:(.text+0x263): undefined reference to `np::np()'
/usr/bin/ld: rnet.cpp:(.text+0x317): undefined reference to `np::np()'
/usr/bin/ld: ./../exe//libuttu.a(peer.o): in function `Peer::Connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/uton/code/Concord/uttu/src/peer.cpp:43: undefined reference to `void np::target<np::_tf>(np::_tf)'
/usr/bin/ld: ./../exe//libuttu.a(relay.o): in function `Relay::Foward()':
/home/uton/code/Concord/uttu/src/relay.cpp:40: undefined reference to `np::np()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:8: r] Error 1
运行art libuttu.a
返回
linux.o
uttu.o
timeout.o
peer.o
relay.o
sec.o
np.o
我的测试脚本包括主头文件uttu.hpp
,它本身引用np
头文件,在 protocols.hpp
名称下,
存档文件的路径是正确的,存档本身包含正确的目标文件,并且测试脚本引用了主头文件,其中包含正确的定义。
我被困在可能出问题的地方。
I'm building a static library for a small project, and when I compile it with ar
, it correctly links.
When I go to include the relevant header file and link the test script to the archive;
LINK = -lpthread -lcryptopp -L./path/to/archive/ -luttu
r: ../inc/uttu.hpp
g++ -std=c++20 rnet.cpp -o r.out $(LINK)
I get linker errors;
/usr/bin/ld: /tmp/cc7h6RHu.o: in function `main':
rnet.cpp:(.text+0x263): undefined reference to `np::np()'
/usr/bin/ld: rnet.cpp:(.text+0x317): undefined reference to `np::np()'
/usr/bin/ld: ./../exe//libuttu.a(peer.o): in function `Peer::Connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/uton/code/Concord/uttu/src/peer.cpp:43: undefined reference to `void np::target<np::_tf>(np::_tf)'
/usr/bin/ld: ./../exe//libuttu.a(relay.o): in function `Relay::Foward()':
/home/uton/code/Concord/uttu/src/relay.cpp:40: undefined reference to `np::np()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:8: r] Error 1
Running ar t libuttu.a
returns
linux.o
uttu.o
timeout.o
peer.o
relay.o
sec.o
np.o
My test script includes the main header file, uttu.hpp
, which itself refers to the np
header file, under the name of protocols.hpp
The path to the archive file is correct, the archive itself contains the correct object file, and the test script refers to the main header file, which includes the correct definitions.
I'm stuck on what could be going wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读此< /a> 所以问题,我意识到我错过了一个被覆盖的虚拟成员。
After reading this SO question, I realized that I had missed an overridden virtual member.