我尝试编译并使用svn trunk中的clang。我基本上尝试按照here的指示:
svn co -q http://llvm.org/svn/llvm-project/llvm/trunk llvm
svn co -q http://llvm.org/svn/llvm-project/cfe/trunk llvm/tools/clang
svn co -q http://llvm.org/svn/llvm-project/clang-tools-extra/trunk llvm/tools/clang/tools/extra
svn co -q http://llvm.org/svn/llvm-project/compiler-rt/trunk llvm/projects/compiler-rt
mkdir llvm_build_release
cd llvm_build_release
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/usr/local -DLLVM_TARGETS_TO_BUILD=host ../llvm
make -j12
make install
上面,我将clang配置为安装在自定义位置~/usr/local
,因为我希望能够在不更改默认环境的情况下使用它。
然后我创建一个简单的test.cpp:
#include <iostream>
int main(int argc, const char* argv[]){
std::cout << "Hello world\n";
return 0;
}
并尝试编译它:
~/usr/local/bin/clang++ test.cpp -o test
但收到错误消息:
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
(使用clang的系统版本,相同的编译工作正常)。
如果我手动输入要使用的标准库,它可以正常工作
~/usr/local/bin/clang++ -std=c++11 -stdlib=libstdc++ -I/usr/include/c++/4.2.1/ -L/usr/lib test.cpp -o test
问题是:如何从源配置,编译和安装clang,以便我做 而不是必须输入这些标准库设置,而只需输入普通的~/usr/local/bin/clang++ test.cpp -o test
?我安装了macports,其标准库版本和包含文件,如果有帮助的话。