Compiling std::string with clang

At work I also have a RHEL 5 based environment and have to live with g++ v4.1.2 headers. (Later I’ll switch to libc++.)

Anyway I got around the compile error you descibe

> error: weakref declaration must have internal linkage
> extern __typeof(pthread_once) __gthrw_pthread_once __attribute__
> ((__weakref__("pthread_once")));

by defining away weakref thus:

clang++ -D’weakref(X)=’ …

(writing this from memory, so I may err.)

Hope this helps,

Gabor

Im sitting here in front of a new iMac:
(a) I installed the latest XCode and its command line tool.
(b) I also installed clang-3.1 and clang-3.2 from MacPorts.

Now I can not compile a simple program "main.cc" like

First: which clang++ are you running?

On this machine I see
$ which clang++
/usr/bin/clang++
$ clang++ -v
Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.0.0
Thread model: posix

after installing just the XCode command line tools (nothing from
MacPorts), and while

$ clang++ -std=c++11 small.cc
small.cc:2:10: fatal error: 'type_traits' file not found
#include <type_traits>
         ^
1 error generated.

fails, with -stdlib=libc++ the command

$ clang++ -std=c++11 -stdlib=libc++ small.cc
$ ./a.out

works as expected.

-- James

Thanks James,

clang from Xcode works. But selecting any clang variant from MacPorts fails!

So I will go there to complain.

Michael

MacPorts needs to start installing libc++ headers relative to the clang binaries it installs; they can look at where those headers land in an Xcode-installed Clang.

  - Doug

As an aside, we strongly encourage people to use compilers from Xcode
releases when developing for Apple platforms. You are, of course, free to
disregard this, but we do a lot of platform-specific testing and qualification
of official Apple builds that is not generally done for the open-source releases.
Despite the (currently) similar numbering scheme, they are very different
releases.

John.