![](/img/trans.png)
[英]What is the idiomatic way in CMAKE to add the -fPIC compiler option?
[英]What's -fPIC compile option?
今天,當嘗試使用mongodb c ++客戶端構建so lib項目時,出現錯誤:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libmongoclient.a(connection_factory.o): relocation R_X86_64_32S against `_ZTVN5mongo17AScopedConnectionE' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libmongoclient.a: error adding symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在-fPIC上進行了搜索,但一無所獲。 在哪里可以找到有關此文件的文檔? 這是什么? 我正在使用clang ++進行構建。
PIC代表位置獨立代碼。 引用man gcc:
如果目標機器支持,則發出與位置無關的代碼,該代碼適用於動態鏈接並避免對全局偏移表的大小進行任何限制。
您在編譯共享庫時未在編譯時打開可重定位代碼。 強烈建議在構建共享庫時使用位置無關代碼(PIC或PIE)。
有關更多詳細信息,請參考http://en.wikipedia.org/wiki/Position-independent_code 。
該系統存在一個錯誤,您不能使用.o
或.a
編譯的中間文件來生成動態lib(xx.so文件),您可以嘗試直接使用.cpp或.c文件來生成動態lib,您也可能會看到此鏈接來修復此錯誤(鏈接網站)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.