溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

gcc編譯選項

發(fā)布時間:2020-09-06 16:09:36 來源:網(wǎng)絡(luò) 閱讀:1837 作者:清風(fēng)徐來918 欄目:開發(fā)技術(shù)


(1)fpic 和 fPIC 區(qū)別

在64位下編譯動態(tài)庫的時候,經(jīng)常會遇到下面的錯誤

/usr/bin/ld: /tmp/ccQ1dkqh.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC


Use -fPIC or -fpic to generate code. Whether to use -fPIC or -fpic to generate code is target-dependent. The -fPIC choice always works, but may produce larger code than -fpic (mnenomic to remember this is that PIC is in a larger case, so it may produce larger amounts of code). Using -fpic option usually generates smaller and faster code, but will have platform-dependent limitations, such as the number of globally visible symbols or the size of the code. The linker will tell you whether it fits when you create the shared library. When in doubt, I choose -fPIC, because it always works.


-fPIC: 總是能夠工作,但可能產(chǎn)生的代碼較大

-fpic: 通常能產(chǎn)生更快更小的代碼,但有平臺限制。



(2)編譯選項 -static 的作用

gcc編譯選項gcc編譯選項



(3)-march 指定目標(biāo)架構(gòu)選項

-march選項就是就是指定目標(biāo)架構(gòu)的名字,gcc就會生成針對目標(biāo)架構(gòu)優(yōu)化的目標(biāo)代碼,如-march=prescott會生成針對i5或i7的目標(biāo)碼,從而充分發(fā)揮cpu的性能。

自gcc4.2,引入了 -march=native ,從而允許編譯器自動探測目標(biāo)架構(gòu)并生成 針對目標(biāo)架構(gòu)優(yōu)化的目標(biāo)代碼 ,這比手工設(shè)置要安全的多。

通過下面的命令查詢當(dāng)前機(jī)器的架構(gòu)名稱,比如:


#gcc -march=native -Q --help=target | grep march

 -march=                     haswell


有的時候編譯會報 "no such instruction", (沒有這個機(jī)器指令)

解決的方案:

1.makefile 中刪掉 -march=native

2.找到正確的目標(biāo)框架名稱設(shè)置


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI