1. 程式人生 > >Mac OS X 下命令列編譯錯誤: ld: library not found for -lcrt1.10.6.o

Mac OS X 下命令列編譯錯誤: ld: library not found for -lcrt1.10.6.o

在 Mac OS X 的 10.8.3 的版本中,使用命令列執行 configure 時,生成下面的錯誤:
WenBi-MacBook:tcpdump-4.4.0 wenbi$ ./configure checking build system type... x86_64-apple-darwin12.3.0 checking host system type... x86_64-apple-darwin12.3.0 checking for gcc... gcc checking whether the C compiler works... no configure: error: in `/Users/wenbi/Downloads/tcpdump-4.4.0':
configure: error: C compiler cannot create executables See `config.log' for more details
檢視 config.log 檔案的內容,會看到更詳情的錯誤資訊:
configure:2755: gcc    conftest.c  >&5  81 ld: library not found for -lcrt1.10.6.o  82 collect2: ld returned 1 exit status  83 configure:2759: $? = 1  84 configure:2797: result: no  85 configure: failed program was:  86 | /* confdefs.h */  87 | #define PACKAGE_NAME ""  88 | #define PACKAGE_TARNAME ""  89 | #define PACKAGE_VERSION ""  90 | #define PACKAGE_STRING ""  91 | #define PACKAGE_BUGREPORT ""  92 | #define PACKAGE_URL ""  93 | /* end confdefs.h.  */  94 |  95 | int  96 | main ()  97 | {  98 |  99 |   ; 100 |   return 0; 101 | } 102 configure:2802: error: in `/Users/wenbi/Downloads/tcpdump-4.4.0': 103 configure:2804: error: C compiler cannot create executables
上面用紅色標註的資訊,說明 gcc 編譯器找不到 C 的執行時庫。這是因為沒有把 xocde 提供的標頭檔案目錄和庫目錄使用環境變數匯出,在命令列中使用 gcc 時,找不到相應的標準標頭檔案和庫檔案。 開啟使用者目錄下的 .bash_profile 檔案,新增如下內容:
export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include
export LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib

重新執行一個新的 bash 視窗,重新執行 configure/make/make install。