Skip to content
Advertisement

Error while linking static library to test script

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.

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement