Clang 3.3 libc++ problem on 9-STABLE

J David j.david.lists at gmail.com
Tue Jul 9 22:50:51 UTC 2013


With SVN version r253119, we are seeing strange errors from iostream while
attempting to use the new clang 3.3 with libc++ on 9-STABLE.

This program:

------------------- start here ----------------------
#include <iostream>

int main() {
std::cout << "This is a test." << std::endl;
return 0;
}
----------------- end here --------------------

Produces this output when compiled:

$ clang++ -std=c++11 -stdlib=libc++ -v -o example example.cc
FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610
Target: x86_64-unknown-freebsd9.1
Thread model: posix
 "/usr/bin/clang++" -cc1 -triple x86_64-unknown-freebsd9.1 -emit-obj
-mrelax-all -disable-free -main-file-name example.cc -mrelocation-model
static -mdisable-fp-elim -masm-verbose -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -v -resource-dir
/usr/bin/../lib/clang/3.3 -stdlib=libc++ -std=c++11 -fdeprecated-macro
-fdebug-compilation-dir /data/jdw -ferror-limit 19 -fmessage-length 80
-mstackrealign -fobjc-runtime=gnustep -fobjc-default-synthesize-properties
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics
-backend-option -vectorize-loops -o /tmp/example-fet9b9.o -x c++ example.cc
clang -cc1 version 3.3 based upon LLVM 3.3 default target
x86_64-unknown-freebsd9.1
ignoring nonexistent directory "/usr/bin/../lib/clang/3.3/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/include/clang/3.3
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1
--hash-style=both --enable-new-dtags -o example /usr/lib/crt1.o
/usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/example-fet9b9.o -lc++
-lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/tmp/example-fet9b9.o: In function `std::__1::basic_ostream<char,
std::__1::char_traits<char> >& std::__1::operator<<
<std::__1::char_traits<char> >(std::__1::basic_ostream<char,
std::__1::char_traits<char> >&, char const*)':
example.cc:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x4b0):
undefined reference to `.LBB1_29'
clang++: error: linker command failed with exit code 1 (use -v to see
invocation)

Compiling with either -std=c++11 or -stdlib=libc++ but not both yields a
ton of linker errors about the mismatches between the header files and
library contents.  (Expected.)

Compiling with neither produces a working executable using the Gnu 4.2
headers and libstdc++.  So the problem appears specific to libc++.

It feels like the linker command line (shown with -v above) being generated
by clang++ isn't right.  I might expect to see libcxxrt.so.1 there.  (It is
present in /lib.)  But manually adding that doesn't appear to help.

What I'm less sure of is whether this is a clang issue or whether
"-std=c++11 -stdlib=libc++" are simply not the right flags to be using
here.  (Although they are what we widely use on other platforms, e.g. Mac,
and appear to be trying to get the right include files and library here,
namely /usr/include/c++/v1 and /usr/lib/libc++.so.)

The system is built with what I understand to be the full suite of
clang/libc++ options in /etc/make.conf:

#  Use clang
CC=clang
CXX=clang++
CPP=clang-cpp
WITH_LIBCPLUSPLUS=yes

Thanks for any advice!


More information about the freebsd-stable mailing list