我正在尝试在我的 Mac 上“干净”地构建一个 C++ 程序。我所说的干净是指不包含任何我未明确指定的内容。
我的 gcc 安装位于:
/Applications/gcc471/
到目前为止,我可以使用
进行编译-nostdinc++
通过包含
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/x86_64-apple-darwin12.0.0
和做
g++ -c *.cpp $(GPP-INCLUDES) -nostdinc++
我对此非常满意。但是,我正在尝试使用
进行编译-nostdinc
而且看起来,无论我包含多少条路径都是这样
/usr/local/include
/usr/include
....
我遇到了一堆这样的错误:
/Applications/gcc471/include/c++/4.7.1/tr1/cmath: At global scope:
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:156:11: error: ‘::double_t’ has not been declared
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:157:11: error: ‘::float_t’ has not been declared
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:160:11: error: ‘::acosh’ has not been declared
...
有谁知道如何在 mac 上使用 -nostdinc 从头开始完全构建一个 cpp 程序?
最佳答案
我能够使用 -nostdinc 进行编译,但并非如我所希望的那样没有 -I/usr/include/。我不相信 Xcodes llvm/clang/gcc4.2(真的很旧)/不是真正的 GCC 废话。所以我从头开始下载 GCC,并使用此处的指南从源代码构建它:http://staticimport.blogspot.ca/2012/02/building-gcc-462-on-os-x-lion.html
问题是 libstdc 似乎不再随 gcc 一起提供,只有 libstdc++。所以所有的 .hpp 文件都在我的 GCC 目录中,但是真正老的头文件,例如 locale.h(从 1993 年开始),似乎只随 libstdc XCode 安装到/usr/include。我将继续寻找要安装的 vanilla libstdc,但目前,这些是我可以包含以进行编译的最小和最“GNU”目录:
...
#FOR -nostdinc++
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/x86_64-apple-darwin12.0.0
#for -nostdinc
GPP-INCLUDES += -I/Applications/gcc471/lib/gcc/x86_64-apple-darwin12.0.0/4.7.1/include/
GPP-INCLUDES += -I/usr/local/include
GPP-INCLUDES += -I/usr/include/ #bahhhhh cant get away
g++ -c *.cpp $(GPP-INCLUDES) -nostdinc++ -nostdinc -std=c++11
关于c++ - mac 尝试使用 -nostdinc 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19543858/