一. 前言
? ? ? ? 在編譯開源軟件的時候,有時會遇到"configure: error: C compiler cannot create executables"的錯誤,表示不能生成可執(zhí)行文件。本文以編譯curl-7.40.0為例,模擬出這種錯誤,并講解解決這種錯誤的方法。錯誤輸出如下:
[root@192 curl-7.40.0]# ./configure LIBS=-lopenssl
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether to enable debug build options... no
checking whether to enable compiler optimizer... (assumed) yes
checking whether to enable strict compiler warnings... no
checking whether to enable compiler warnings as errors... no
checking whether to enable curl debug memory tracking... no
checking whether to enable hiding of library internal symbols... yes
checking whether to enable c-ares for DNS lookups... no
checking for path separator... :
checking for sed... /usr/bin/sed
checking for grep... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ar... /usr/bin/ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/betterman/opensource/curl-7.40.0':
configure: error: C compiler cannot create executables
See `config.log' for more details
二. 錯誤解析
? ? ? ? 根據(jù)最后一句輸出,我們需要參考config.log的內(nèi)容。從config.log文件中,可以找到如下一段內(nèi)容:
configure:4216: checking whether the C compiler works
configure:4238: gcc ? ?conftest.c -lopenssl >&5? ? ? ? ? ? ? ? ? ?(1)
/usr/bin/ld: cannot find -lopenssl? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (2)
collect2: error: ld returned 1 exit status
configure:4242: $? = 1
configure:4280: result: no
configure: failed program was:
| /* confdefs.h */? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (3)
| #define PACKAGE_NAME "curl"
| #define PACKAGE_TARNAME "curl"
| #define PACKAGE_VERSION "-"
| #define PACKAGE_STRING "curl -"
| #define PACKAGE_BUGREPORT "a suitable curl mailing list: http://curl.haxx.se/mail/"
| #define PACKAGE_URL ""
| /* end confdefs.h. ?*/
|?
| int main (void)
| {
|?
| ?;
| ?return 0;
| }
configure:4285: error: in `/home/wenyong/opensource/curl-7.40.0':
configure:4287: error: C compiler cannot create executables? ? ? ? ? ? ? ? (4)
See `config.log' for more details
? ? ? ? 從(1)可知,gcc會編譯conftest.c文件并且需要鏈接libopenssl.so,所以報(2)的錯誤,表示編譯時找不到libopenssl.so庫,conftest.c的內(nèi)容是從(3)開始,最后產(chǎn)生了(4)處的錯誤。
三. 解決方法
? ? ? ? 由上可知,可以得出結論:軟件包在configure的時候,configure會根據(jù)用戶指定的編譯選項編譯conftest.c文件,由此來預檢查編譯時要用到的gcc,動態(tài)庫等是否可以找到,盡早讓用戶檢查錯誤。
? ? ? ? 本例的錯誤是由于libopenssl.so找不到,所以解決方法有:
1. 通過LDFLAGS選項指定libopenssl.so所在的路徑,例如:
./configure LIBS=-lopenssl?LDFLAGS=/root/libopenssl/usr/lib
2. 直接使用./configure編譯
? ? ? ? 如果編譯curl不需要用到openssl的庫,可以不鏈接。文章來源:http://www.zghlxwxcb.cn/news/detail-545967.html
四. 總結
? ? ? ? 本文講解了解決"configure: error: C compiler cannot create executables"問題出現(xiàn)的原因與解決的思路:configure運行的時候需要使用用戶指定的選項編譯conftest.c文件,但是由于選項指定的gcc或動態(tài)庫找不到,導致編譯報錯,解決的方法是指定gcc和動態(tài)庫的路徑。文章來源地址http://www.zghlxwxcb.cn/news/detail-545967.html
到了這里,關于configure: error: C compiler cannot create executables錯誤解析的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!