• 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: Linking problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linking problem


  • Subject: Re: Linking problem
  • From: Jeremy Pereira <email@hidden>
  • Date: Wed, 9 Dec 2009 11:18:00 +0000

Just a small observation.  If you had included the text of your linker errors in your original post, you would have immediately got the correct answer - probably.  "Include *all* relevant information" is good advice.

The C++ compiler applies a technique called name mangling to function names to differentiate overloaded function definitions.  Name mangling adds a sequence of apparently random letters to the end of each function name which actually encodes the types of the parameters.  The C compiler does not do this, so if calling a function compiled by the C compiler in C++ code you have to tell the C++ compiler not to apply name mangling when it comes to the function declaration.  This is what the extern "C" {...} thing does.

Name mangling is one reason why it's very difficult to link libraries compiled with a different C++ compiler into your code. Different C++ compilers have different name mangling conventions.  Sometimes different versions of the same C++ compiler have different name mangling conventions.  For instance a C++ library compiled with gcc 2.95 cannot be linked to a C++ program compiled with gcc 4.2.

Anyway, pretty much everybody who has ever tried to mix their own C code with their own C++ code has hit the same problem.  After a while writing the

#ifdef __cplusplus
 extern "C" {
 #endif

construct in your headers gets to be automatic.  In fact Xcode has C++ macros to help.

On 8 Dec 2009, at 14:12, David Gagnon wrote:

> I fixed my linking problem. Here is the solution:
>
> http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.4
>
> Very interesting to read...
>
> On 2009-12-07 17:09, "David Hayes" <email@hidden> wrote:
>
>> It's been while, I think if you run nm on the file from the command line it will give you what you want.  You can also pipe the output to grep on the symbol you are looking for it will save some searching.
>>
>> Don't know if XCode has a graphical front end.
>>
>> Dave Hayes
>>
>> On 2009-12-07, at 4:18 PM, David Gagnon wrote:
>>
>>> Hi,
>>>
>>> I am trying to convert our C++ application from CodeWarrior to Xcode 3.2 (on OSX 10.6). Everything goes well except that I cannot link to one specific library (framework). I got a couple of undefined symbols and I cannot figure out why Xcode does not find those symbols.
>>>
>>> Is there a way to extract symbols from a library and compare to exported symbols in my application object files?
>>>
>>> Thanks!
>>>
>>> David
>>> _______________________________________________
>>> 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
>>
>>
> _______________________________________________
> 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


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
 _______________________________________________
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: 
 >Re: Linking problem (From: David Gagnon <email@hidden>)

  • Prev by Date: Re: How to add a generated file to a project's resources
  • Next by Date: Re: Can't Compile cpp file from editor?
  • Previous by thread: Re: Linking problem
  • Next by thread: Re: Adding existing svn files to new project
  • Index(es):
    • Date
    • Thread