• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Douglas Norton <email@hidden>
  • Date: Sun, 16 Aug 2009 09:25:46 -0700

On Aug 16, 2009, at 8:27 , Alastair Houghton wrote:

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.


Thanks for your comments. Adding the .mm file seems like smoke and mirrors, so I want to avoid that if I can. Building a dynamic library is not an option since the iPhone does not support them, and I need my library to work on the iPhone.

The best solution I have so far is the -lstdc++ directive added to the Other Linker Flags, as that addresses the problem directly.

I was just hoping that there was something I overlooked when making my library, so that linking the C++ runtime could be made to be automatic.

Regards,

Douglas

--

Douglas J. Norton
_______________________________________________
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


References: 
 >ld errors when Cocoa app linking C++ via intermediate ObjC++ library (From: Douglas Norton <email@hidden>)
 >Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: Recommendations for strip(1)? Was: gdb: "No line number info...."
  • Next by Date: Running otest in Instruments
  • Previous by thread: Re: ld errors when Cocoa app linking C++ via intermediate ObjC++ library
  • Next by thread: Recommendations for strip(1)? Was: gdb: "No line number info...."
  • Index(es):
    • Date
    • Thread