Mar*_*tin 5 clang clang++ sublimetext2
我有以下代码
#include <iostream>
#include <cstdint>
using namespace std;
int main ()
{
int32_t spam;
spam=5;
cout << "Hello World! We like " << spam << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,这很好地编译clang++ -stdlib=libc++ cpptest.cpp.但是,Sublime Text 2的优秀SublimeClang解析器似乎并不理解它.我想这可能是因为它使用clang -x c++而不是clang++,并试图使用clang -x c++ -std=c++11 -stdlib=libc++ cpptest.cpp(或其中的各种排列)编译我的上面的代码段,但是这很糟糕,抱怨链接器.
所以我的问题是,有什么clang++不同clang -x c++?是否可以使用clang -x c++而不是使用clang++?来编译上面的代码片段?
我的机器是2012款运行Mountain Lion的MacBook Air.
现在回到工作中,我已经玩了更多,并比较了不同版本的详细输出.
clang -x c++当我跑步时,clang -v -x c++ -stdlib=libc++ cpptest.cpp我得到了
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name cpptest.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/clang-module-cache -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/me/Desktop -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/cpptest-1eOyZn.o -x c++ cpptest.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.1
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/4.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o a.out /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/cpptest-1eOyZn.o -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
[snip]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
clang++当我打电话时,clang++ -v -stdlib=libc++ cpptest.cpp我得到以下内容.
clang++ -v -stdlib=libc++ cpptest.cpp
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name cpptest.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/clang-module-cache -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/me/Desktop -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/cpptest-E7FTDV.o -x c++ cpptest.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.1
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/4.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o a.out /var/folders/8m/b4wllzbs67d9zxcj1dd8q6912jclkf/T/cpptest-E7FTDV.o -lc++ -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Run Code Online (Sandbox Code Playgroud)
我能找到的唯一主要区别是,当我用-x c++旗帜运行clang时,-lc++标志不会在开头的行的末尾添加"/usr/bin/lb".当我改为编译时clang -v -lc++ -x c++ -stdlib=libc++ cpptest.cpp,一切正常.我仍然不明白clang++和clang -x c++命令究竟有什么不同,但这似乎使我的示例程序至少编译,并且似乎表明这些命令与链接器做了不同的事情.
这整个小虫狩猎开始于我试图弄清楚如何让Sublime Text 2停止抱怨我实际上有效的代码,现在我想我已经得到了它.所需要的只是按照这里的说明并设置包含
/usr/lib/c++/v1
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/ext
Run Code Online (Sandbox Code Playgroud)
在SublimeClang.sublime-settings文件中.
| 归档时间: |
|
| 查看次数: |
2287 次 |
| 最近记录: |