1

Possible Duplicate:
Linker error on Linux: “undefined reference to”

I link together a shared library like this:

core : $(CORE_OBJS) | bin
    $(CC) $(LFLAGS) -o bin/libcbitcoin$(LIBRARY_EXTENSION) $(CORE_OBJS)

Which produces the library file libcbitcoin.2.0.so.

But when executables which link to the library are made the linker complains that there are undefined references to each symbol that comes up. The makefile links the executables like this:

$(TEST_BINARIES): bin/%: build/%.o
    $(CC) -lcbitcoin.$(LIBRARY_VERSION) -lpthread -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcbitcoin-network.$(LIBRARY_VERSION) -lcbitcoin-file-ec.$(LIBRARY_VERSION) -lcbitcoin-storage.$(LIBRARY_VERSION) -lcbitcoin-rand.$(LIBRARY_VERSION) -L/opt/local/lib -levent_core -levent_pthreads -lcrypto -L$(BINDIR) $< -o $@

This gives the linker option -lcbitcoin.2.0.

I only get this problem when I try to build for Linux Mint and not OSX. The full makefile is here: https://github.com/MatthewLM/cbitcoin/blob/newNetworkCode/Makefile.in

The autoconf file is here (if in any case it is important): https://github.com/MatthewLM/cbitcoin/blob/newNetworkCode/configure.ac

Thanks for any help.

Community
  • 1
  • 1
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122

1 Answers1

6

edit: linker ordering.

You don't have to specify the library extension to the linker line. Just a -lcbitcoin should be sufficient.

Also, the order of libraries passed to the linker can be important. The ordering the opposite of what you might expect -- you should specify a library after specifying the objects that require it. See: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

sheu
  • 5,653
  • 17
  • 32
  • 1
    "you should specify a library after specifying the objects that require it." Dang it, always something this easy! Also, if you have two libs that depend on the eachother like I did, I had to do -lliba -llibb -lliba – Cruel Jan 31 '14 at 17:17