2014-10-19 18 views
0

我有这样的片段:使用stdlib=libc++锵不承认的std :: shared_ptr的用的libstdC++

main.cpp:4:8: error: no member named 'shared_ptr' in namespace 'std' 
    std::shared_ptr<int> p(new int); 
    ~~~~~^ 

它运作良好:

#include <memory> 
int main() { 
    std::shared_ptr<int> p(new int); 
} 

如果我clang++ -std=c++0x -stdlib=libstdc++ main.cpp编译我得到这个错误代替。该++的libstdc的版本是6.0.9,编译器是

$ clang++ --version 
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) 
Target: x86_64-apple-darwin13.3.0 
Thread model: posix 

我看到了同样的结果使用clang version 3.5.0 (tags/RELEASE_350/final)时。

我已经意识到,它的作品,如果我用tr1,但这似乎不太便携式对我说:

#include <tr1/memory> 
int main() { 
    std::tr1::shared_ptr<int> p(new int); 
} 

那么,是不是有可能使用std::shared_ptr铿锵和libstdC++?

+0

这取决于你的GCC/libstdC++版本。很可能你正在一个发布GCC旧版本的平台上。 – 2014-10-19 04:18:34

+1

正如我所猜测的,libstdC++ 6.0.9附带GCC 4.2.1。您应该考虑更新GCC(即通过自制软件)。我认为您必须使用指向您的GCC 4.8安装的'--with-gcc-toolchain'重新编译clang。 – 2014-10-19 04:23:39

回答

1

Mac发布了一个非常旧的GCC版本(4.2.1),它当然带有一个非常老的libstdC++。该Getting Started页面LLVM说:

If you intend to use Clang's C++ support, you may need to tell it how to find your C++ standard library headers. In general, Clang will detect the best version of libstdc++ headers available and use them - it will look both for system installations of libstdc++ as well as installations adjacent to Clang itself. If your configuration fits neither of these scenarios, you can use the --with-gcc-toolchain configure option to tell Clang where the gcc containing the desired libstdc++ is installed.

这将是做到这一点的最简单的方法,只需将其指向您的现代GCC安装。如果你不想重新编译铛,那么你可以尝试跟踪该mailing list说明:

Yes, of course. Finding the standard library is no magic, you can simply add some -isystem, -L, and possibly -Wl,-rpath arguments to clang++ when using it. Use the -v option to see what clang is using by default, so you can just add the same with s/4.4/4.7/g. If clang puts one of its own directories first (before the gcc ones), be sure to specify it again yourself so it still ends up first. You can even try some flags like -nostdinc++ to clean up a bit (again, check with -v that the list makes sense).

-- Marc Glisse

请记住,如果你设法让铛++有新的libstdC++,那的libstdC++和libc的工作++是binary incompatible。这意味着任何编译为一个的库(例如Boost)都必须与其他库重新编译。

相关问题