Clangについて良いことを聞いたので、Clangを試してみることにしました。そして、C++11の機能のいくつかを試してみたかったのです。それで、いつものように、私は単純なhelloworldプログラムから始めました。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world" << endl;
return 0;
}
GCCを使用して正常にコンパイルされたものは、Clangではコンパイルされません。代わりに、このエラーが発生します。
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
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 test.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/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/clang-module-cache -fdeprecated-macro -fdebug-compilation-dir /Users/alexanderstein/Desktop/build -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/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/test-4P1Ij1.o -x c++ /Users/alexanderstein/Desktop/Programming/Sandbox/C_C++/test.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/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/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/test-4P1Ij1.o -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in test-4P1Ij1.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test-4P1Ij1.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test-4P1Ij1.o
"std::cout", referenced from:
_main in test-4P1Ij1.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in test-4P1Ij1.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in test-4P1Ij1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)