[英]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.