Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library
Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library
- Subject: Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library
- From: Alastair Houghton <email@hidden>
- Date: Sun, 16 Aug 2009 16:27:54 +0100
On 16 Aug 2009, at 00:48, Douglas Norton wrote:
When the application tries to link, it does not appear to be
including the C++ support needed for my C++ static library.
[snip]
I have discovered that I can solve this by either renaming one or
more source files in the application from .m to .mm, or simply
'getting info' on a .m file and changing the type to
sourcecode.cpp.objcpp. When I do this the ld command stops using /
Developer/usr/bin/gcc-4.0, and instead invokes /Developer/usr/bin/g+
+-4.0.
[snip]
Is there any way to have the ObjectiveC++ library instruct Xcode to
use a linker command that supports C++, whenever that library is
linked into an application?
I don't know of anything OTOH, and indeed this is a general problem
with static libraries that use C++ on most systems---an otherwise C++-
free program that links with such a library needs to be aware that it
must also link with the C++ RTL. (Similar problems occur for
libraries built in other languages too, but the C++ case is by far the
most common.)
If, rather than a static library, you were to generate a dylib or a
framework, the problem would go away, because the dylib/framework will
include the C++ standard library dylib automatically.
If you must ship a static library, what you *could* do is tell your
customers to add the libstdc++ dylib (from /usr/lib) to their
project. *Or* you could tell them to add "-lstdc++" to the Other
Linker Flags, which achieves the same effect. Another alternative
that might suit is for you to ship a small .cc or .mm file that they
can add to their project; it doesn't have to do anything other than
act as a flag for Xcode to let it know that there is C++ code in the
project.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden