c++ - Same STL files with different compilers -
there 2 binary files obtained same source file: 1 compiled clang++-3.6 , other 1 g++-4.8. in call function stl (std::unique, in particular) gdb brings me same file: /usr/include/c++/4.8/bits/stl_algo.h.
i expected implementations different each compiler though. clang , gcc share parts of c++ implementations?
i expected implementations different each compiler though. clang , gcc share parts of c++ implementations?
it's not share same c++ implementations, rather both compilers link same standard c++ library default on system.
i presume on linux, programs installed package manager link against libstdc++ (provided g++).
by default, when compiling clang++, libstdc++ used, when include iostream example, uses 1 /usr/include/c++/4.8.
if want link against llvm c++ library, need install "libc++-dev" package (name may vary depending on distro) , compile using: -stdlib=libc++ (instead of default: -stdlib=libstdc++).
example:
test.cpp:
#include <iostream> int main(int argc, char *argv[]) { std::cout << "hello world!!!\n"; return 0; }
compiling using:
$ clang++ -stdlib=libc++ -o test test.cpp
will use header /usr/include/c++/v1 (from llvm)
but compiling using:
$ clang++ -stdlib=libstdc++ -o test test.cpp # or (assuming default on system libstdc++) $ clang++ -o test test.cpp
will use header /usr/include/c++/4.8 (from g++)
Comments
Post a Comment