Saturday, April 19, 2014

[MacOS] MacOS 10.9(Mavericks)上clang对未知参数报错的问题

在MacOS 10.9上用pip安装一个库的时候发现clang报错
$ sudo pip install mysql-python
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.16/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

error: command 'cc' failed with exit status 1

原因

XCode 5.1 以后, XCode的默认编译器clang会对所有它不认识的命令行flag报错 http://kaspermunck.github.io/2014/03/fixing-clang-error/

解决方法

参照这里给出的方案: http://stackoverflow.com/questions/22313407/clang-error-unknown-argument-mno-fused-madd-python-package-installation-fa

在运行安装命令的时候先修改CFLAGS和CPPFLAGS
$ export CFLAGS=-Qunused-arguments
$ export CPPFLAGS=-Qunused-arguments
$ sudo -E pip install mysql-python
注意由于安装过程中需要sudo, 所以为了让环境变量传递过去, 需要加上-E选项

No comments: