如何在configure時,將編譯參數傳入,改變默認的編譯器gcc成arm-linux-gcc

http://www.51zxw.net/study.asp?vip=1368926 

http://blog.163.com/againinput4@yeah/blog/static/1227642712009623053497/

如何在configure時,將編譯參數傳入,改變默認的編譯器gcc成arm-linux-gcc

【問題】

想要用交叉編譯工具arm-linux-gcc去編譯lrzsz,
但是在./configure的時候,無法用--host=arm-linux或--build=arm-linux或--target=arm-linux等傳入此編譯器參數。

【解決過程】

按照INSTALL中的介紹,也是常用的方法,在configure的時候,加上--host=arm-linux,結果沒有實現我們要的效果,沒有將編譯器從默認的
gcc改成arm-linux-gcc,編譯器還是用的默認的gcc:

[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 ./configure --host=arm-linux
loading cache ./config.cache
....................
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -O2 ) works... yes
checking whether the C compiler (gcc -O2 ) is a cross-compiler... no
....................

後來經過多次嘗試,最後受默認的
CFLAGS=-O2 ./configure
進行配置所啓發,想到,是否可以將CC參數傳入到configure中,
結果證實,如果沒有自己的cache-file,即時加了對的CC參數,也還是無法傳入:
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure --host=arm-linux
loading cache ./config.cache
....................
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -O2 ) works... yes
checking whether the C compiler (gcc -O2 ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
....................

而且,如果CC參數放在configure後面:
./configure CC=arm-linux-gcc
則不能識別:
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 ./configure CC=arm-linux-gcc
configure: warning: CC=arm-linux-gcc: invalid host type
....................

參數傳遞必須像
CFLAGS=-O2 ./configure
一樣,將參數設置放在configure的前面:
CC=arm-linux-gcc./configure
才能識別的。


必須要自己制定自己的cache-file 然後用./configure進行新配置,加上CC參數,纔會即時生效,編譯器纔可以變成我們要的arm-linux-gcc:
[crifan@localhost lrzsz-0.12.20]$ CC=arm-linux-gcc ./configure --cache-file=cache_file_0 --prefix=/usr/crifan/lrzsz
....................
checking for gcc... arm-linux-gcc
checking whether the C compiler (arm-linux-gcc ) works... yes
checking whether the C compiler (arm-linux-gcc ) is a cross-compiler... yes
checking whether we are using GNU C... yes
....................

否則,就無法將我們的CC參數傳入了:
[crifan@localhost lrzsz-0.12.20]$ CC=arm-linux-gcc ./configure --prefix=/usr/crifan/lrzsz
....................
checking for gcc... (cached) gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
....................

[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure --cache-file=cache_file_0
loading cache cache_file_0
....................
checking for gcc... arm-linux-gcc
checking whether the C compiler (arm-linux-gcc -O2 ) works... yes
checking whether the C compiler (arm-linux-gcc -O2 ) is a cross-compiler... yes
checking whether we are using GNU C... yes


最好此處在加上--prefix=/usr/crifan/lrzsz,表示具體安裝到哪裏
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure --cache-file=cache_file_0 --prefix=/usr/crifan/lrzsz
loading cache cache_file_0
....................
checking for gcc... arm-linux-gcc
checking whether the C compiler (arm-linux-gcc -O2 ) works... yes
checking whether the C compiler (arm-linux-gcc -O2 ) is a cross-compiler... yes
checking whether we are using GNU C... yes
....................

其中,/usr/crifan/lrzsz是已經建立好的,已經存在的文件夾,上面這樣表示編譯後,
將生成的可執行文件安裝拷貝到那個目錄.

【辦法總結】
在./configure的時候,將CC參數放入configure之前,並且要制定cache file,才能完全即時識別編譯器:
CC=arm-linux-gcc ./configure --cache-file=cache_file_0

發佈了153 篇原創文章 · 獲贊 12 · 訪問量 38萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章