[英]GCC doesn't link static library dependency (makefile)
我使用一个静态库,让我们假设cityhash,它已经构建并安装到/ usr / local / lib。 我有一个使用cityhash的文件foo.cxx,例如:
// foo.cxx
u64 get_hash(const std::string &s) {
return CityHash64(s.data(), s.size());
}
我从中建立一个静态库:
gcc -c foo.cxx => foo.o
ar rcs libfoo.a foo.a => libfoo.a
我还有另一个文件bar.cxx,它使用foo.cxx和间接的CityHash函数。 我对其进行编译,并与libcityhash.a和libfoo.a链接,如下所示:
gcc -c bar.cxx => bar.o
gcc -L. -o bar bar.o -lcityhash -lfoo
但这不起作用,链接器抱怨CityHash64是未定义的引用。 怎么了? 当我不创建静态库libfoo.a
一切正常。
看到这个。 您需要编写链接程序args -lfoo -lcityhash
。 需要符号的库应该放在提供符号的库之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.