将静态库链接到测试脚本时出错

发布于 2025-01-10 11:24:02 字数 1245 浏览 0 评论 0原文

我正在为一个小项目构建一个静态库,当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧瑾黎汐 2025-01-17 11:24:02

After reading this SO question, I realized that I had missed an overridden virtual member.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文