[cfe-dev] Current state of libcxx compatibility with libstdc++

Jonathan Roelofs via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 9 06:53:24 PDT 2016



On 8/9/16 4:03 AM, Jeroen Ooms via cfe-dev wrote:
> [ This is probably a FAQ, however Google gives a lot of conflicting and
> outdated information... ]
>
> We are trying to add support for compiling R packages with C++11 code on
> CentOS 6/7 using standard compilers from CentOS/EPEL repositories.
> Because gcc/libstdc++ on CentOS are too old (4.4.7), Tom Callaway has
> recently added libcxx and libcxxabi [1,2] to Fedora/EPEL. We can now
> build C++11 code natively on CentOS with clang:
>
>   clang++ -stdlib=libc++ -std=c++11 example.cpp
>
> Awesome. However for code which links to c++ system libraries (which are
> compiled with gcc) this sometimes results in linking errors. For example
> a test application geometry.cpp [3] which links to the
> "ImageMagick-c++-devel" package:
>
>   clang++ -stdlib=libc++ -std=c++11 geometry.cpp $(pkg-config --cflags
> --libs ImageMagick++)'
>
> This fails with:
>
>   geometry.cpp:(.text+0xd9): undefined reference to
> `Magick::Geometry::Geometry(std::__1::basic_string<char,
> std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
>   geometry.cpp:(.text+0x2ed): undefined reference to
> `Magick::Geometry::operator std::__1::basic_string<char,
> std::__1::char_traits<char>, std::__1::allocator<char> >() const'
>
> Is this expected?

Yes.

> Is there any way we can work around this to link c++
> programs compiled with libcxx against system libraries which are
> compiled with gcc?

"compiled with gcc" isn't the issue. The issue is that you have one set 
of objects *built against libstdc++* and you're trying to link them 
against another set *built against libcxx*. This can only work if your 
interface between them does not contain things from the standard library.

Let me re-iterate: it is ok to link against both standard libraries 
(their symbols won't collide). What's not going to work is to use the 
headers from one library against the binaries from the other.

> If not, might this be possible for future versions of
> libcxx or are the two simply incompatible on this level?

The compatibility you're looking for here is never going to happen.


Jon

>
>
> [1] https://bugzilla.redhat.com/show_bug.cgi?id=1332306
> <https://bugzilla.redhat.com/show_bug.cgi?id=1332306>
> [2] https://bugzilla.redhat.com/show_bug.cgi?id=1332307
> <https://bugzilla.redhat.com/show_bug.cgi?id=1332307>
> [3]
> https://github.com/ImageMagick/ImageMagick/blob/master/Magick%2B%2B/tests/geometry.cpp
> <https://github.com/ImageMagick/ImageMagick/blob/master/Magick%2B%2B/tests/geometry.cpp>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded



More information about the cfe-dev mailing list