最新消息:

MAC OS X 下include头文件缺失引起的问题及解决办法

include admin 10268浏览 0评论

MAC OSX下 include头文件缺失引起的问题及解决办法command line tools 安装

现象

在升级了10.9之后,使用编译安装程序总是报错,提示

error: xxx.h not found

通过使用

locate命令,可以看到系统是存在这个头文件的,但是其并不在我们常见的/usr/include目录下,而是apple自己的SDK目录下.

bogon:pro1 summer$ locate xmlversion.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/libxml2/libxml/xmlversion.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2/libxml/xmlversion.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/libxml2/libxml/xmlversion.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/include/libxml2/libxml/xmlversion.h

而查看/usr目录,并没有我们想要的/usr/include文件夹.

bogon:usr summer$ ls -l
total 7
drwxr-xr-x     5 root  wheel    17082513:05 X11
lrwxr-xr-x     1 root  wheel      3102322:47 X11R6 ->X11
drwxr-xr-x  1045 root  wheel  35530102616:04 bin
drwxr-xr-x   268 root  wheel   911211815:41 lib
drwxr-xr-x   163 root  wheel   5542102323:01 libexec
drwxrwxr-x    18 root  admin    61211814:40local
drwxr-xr-x   243 root  wheel   8262102322:52 sbin
drwxr-xr-x    42 root  wheel   142811815:41 share
drwxr-xr-x     4 root  wheel    136102322:39 standalone

解决办法

通常这个问题是由于系统没有相应的开发环境引起的.不同于常用的linuxmac osx并没有直接提供开发环境.这大概是由于大部分并不需要开发环境,索性官方也不提供了.开发人员反正能自己配置= =.

解决办法也很简单,可以安装xcode.然后通过在菜单中点击安装command line tools来解决.

不过,xcode那么大,一年都开不了一次,一定要安装么?

答案是否定的.apple develop中心提供了直接安装command line tools的方法:

xcode-select--install

安装完毕,再来查看/usr,就能看到熟悉的/usr/include了,里头已经包括了大部分常用的头文件了.

bogon:usr summer$ ls -l
total 8
drwxr-xr-x     5 root  wheel    17082513:05 X11
lrwxr-xr-x     1 root  wheel      3102322:47 X11R6 ->X11
drwxr-xr-x  1045 root  wheel  35530102616:04 bin
drwxr-xr-x   253 root  wheel   860211815:41 include
drwxr-xr-x   268 root  wheel   911211815:41 lib
drwxr-xr-x   163 root  wheel   5542102323:01 libexec
drwxrwxr-x    18 root  admin    61211814:40local
drwxr-xr-x   243 root  wheel   8262102322:52 sbin
drwxr-xr-x    42 root  wheel   142811815:41 share
drwxr-xr-x     4 root  wheel    136102322:39 standalone

后话:

这个问题在我使用10.8.5的时候并没有出现,原因是当时已经安装了xcode以及相应的command line tools了.但是由于升级了新的mavericks,导致环境都变了,相应的command line tools也被删除了,于是就出现了include文件夹不见的情况.

mavericks还是挺好用的,相对来说,电源能用的更久点,而且内存管理也相当给力.就是bug不少,预览的速度很慢.而且flash貌似也有点问题,已经死机过好几回了.

转载请注明:爱开源 » MAC OS X 下include头文件缺失引起的问题及解决办法

您必须 登录 才能发表评论!