[cfe-dev] Adopting libc++, hitting problems on Mac OS X

Dallman, John john.dallman at siemens.com
Fri Sep 28 04:01:55 PDT 2012


> You understand incorrectly.

Oh, good!

> Libc++ is specifically designed so that you can use it in the same process
> as libstdc++.  What you can not do is use it interchangeably with libstdc++.

Right ... so having a process "pure" one library or the other is definitely
safe, but one can be safe with them both in if one does things right.

Now I have to try to write some rules for this for developers who believe C++
is magic and always works right. For applications where large numbers of dylibs
are supplied by third parties. This could be fiddly, since my own understanding
of C++ is not of the very finest.

> For example, if you define a function that takes a std::string, then you
> must pass it a std::string from the same STL that it was compiled with
> (libstdc++ or libc++). Libc++ puts all of its code in a non-standard
> namespace and then imports it into the std namespace, so you will get a
> linker error if you try this.

So "if it links, it will work (in this respect)?"

As regards writing a rule, it sounds like this should work:

  If two separately linked modules (executables or dylibs) have a C++ call
  interface between them, then they must be compiled for the same C++ run-
  time; if they aren't, it (usually) won't link. If C++ is used behind the
  scenes to implement an API that has a C call interface, and C++ objects
  are *never* passed across the interface, then the process can have a
  mixture of libc++ and libstdc++.

thanks very much,

--
John Dallman

-----Original Message-----
From: Dr D. Chisnall [mailto:dc552 at hermes.cam.ac.uk] On Behalf Of David Chisnall
Sent: 28 September 2012 11:46
To: Dallman, John
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] Adopting libc++, hitting problems on Mac OS X

On 28 Sep 2012, at 11:32, Dallman, John wrote:

> As best I understand it, you can't use both libc++ and libstdc++ in the same
> process

You understand incorrectly.  Libc++ is specifically designed so that you can use it in the same process as libstdc++.  What you can not do is use it interchangeably with libstdc++.  For example, if you define a function that takes a std::string, then you must pass it a std::string from the same STL that it was compiled with (libstdc++ or libc++).  Libc++ puts all of its code in a non-standard namespace and then imports it into the std namespace, so you will get a linker error if you try this.

David




More information about the cfe-dev mailing list