最近把macos升級到mojave,順便把xcode也升到了10.1枫振。結(jié)果編譯C代碼的時候持寄,發(fā)現(xiàn)找不到stdio.h
了:
<stdin>:1:19: 致命錯誤:stdio.h:No such file or directory
頭文件包含路徑有問題嗎谬泌?于是用gcc
搜索stdio.h
(gcc幾個編譯選項的解釋見最下面的附錄):
$ echo "#include <stdio.h>" | gcc -v -x c -
使用內(nèi)建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/lto-wrapper
目標(biāo):x86_64-apple-darwin16.1.0
配置為:../configure --prefix=/usr/local/gcc-6.2.0 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3 --disable-multilib --with-sytem-zlib --enable-languages=c,c++
線程模型:posix
gcc 版本 6.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mmacosx-version-min=10.14.0' '-mtune=core2'
/usr/local/gcc-6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/cc1 -quiet -v -D__DYNAMIC__ - -fPIC -quiet -dumpbase - -mmacosx-version-min=10.14.0 -mtune=core2 -auxbase - -version -o /var/folders/23/cb_mbvwd6hg6sj5543x3dj_h0000gn/T//ccsU3P4Z.s
GNU C11 (GCC) 版本 6.2.0 (x86_64-apple-darwin16.1.0)
由 GNU C 版本 6.2.0 編譯乙墙,GMP 版本 6.1.0颖变,MPFR 版本 3.1.4,MPC 版本 1.0.3听想,isl 版本 none
GGC 準(zhǔn)則:--param ggc-min-expand=100 --param ggc-min-heapsize=131072
忽略不存在的目錄“/usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../../x86_64-apple-darwin16.1.0/include”
忽略不存在的目錄“/usr/include”
#include "..." 搜索從這里開始:
#include <...> 搜索從這里開始:
/usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/include
/usr/local/include
/usr/local/gcc-6.2.0/include
/usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed
/System/Library/Frameworks
/Library/Frameworks
搜索列表結(jié)束腥刹。
GNU C11 (GCC) 版本 6.2.0 (x86_64-apple-darwin16.1.0)
由 GNU C 版本 6.2.0 編譯,GMP 版本 6.1.0汉买,MPFR 版本 3.1.4衔峰,MPC 版本 1.0.3,isl 版本 none
GGC 準(zhǔn)則:--param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 012c530f028eade4bd44e1c5c6ad79c2
<stdin>:1:19: 致命錯誤:stdio.h:No such file or directory
編譯中斷蛙粘。
結(jié)果竟然告訴我垫卤,/usr/include
目錄不存在!
在stackoverflow上查了下出牧,原來是xcode挖的坑:
The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
or the Command Line Tools at:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
depending on which is selected using xcode-select.
The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
To make sure that you're using the intended version of the command line tools, run xcode-select -s <path to Xcode> or xcode select -s /Library/Developer/CommandLineTools after installing.
解決方案有兩個,更簡單的是安裝macOS_SDK_headers_for_macOS_10.14.pkg
评抚,不過xcode若干個版本后就不再支持了慨代。
安裝方法如下
$ cd /Library/Developer/CommandLineTools/Packages/
$ open macOS_SDK_headers_for_macOS_10.14.pkg
然后會彈出一個安裝界面侍匙,一直點繼續(xù)想暗,最后/usr/include
總算恢復(fù)正常了债鸡。
附錄
gcc的編譯選項
- '-v': 打印gcc版本信息和編譯過程的詳細(xì)信息
- '-x c': 指定以C語言來編譯
- '-': 指定以標(biāo)準(zhǔn)輸入stdin作為輸入,而不是文件