c++ - GCC doesn't link static library dependency (makefile) -
i use static library, let's assume cityhash, i've build , installed /usr/local/lib. have file foo.cxx uses cityhash, example:
// foo.cxx u64 get_hash(const std::string &s) { return cityhash64(s.data(), s.size()); }
i build static library it:
gcc -c foo.cxx => foo.o ar rcs libfoo.a foo.a => libfoo.a
i have file, bar.cxx, uses foo.cxx , indirectly cityhash function. compile it, , link both libcityhash.a , libfoo.a following:
gcc -c bar.cxx => bar.o gcc -l. -o bar bar.o -lcityhash -lfoo
but doesn't work, linker complains cityhash64 undefined reference. wrong? when not make static library libfoo.a
works fine.
see this. need write linker args -lfoo -lcityhash
. library needs symbol should go before 1 provides it.
Comments
Post a Comment