• 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: Solved: "C" Functions Won't Link Between .mm Files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Solved: "C" Functions Won't Link Between .mm Files


  • Subject: Re: Solved: "C" Functions Won't Link Between .mm Files
  • From: Eric Albert <email@hidden>
  • Date: Tue, 13 Dec 2005 21:41:28 -0800

On Dec 13, 2005, at 9:21 PM, Jerry Krinock wrote:

If I linked my Cocoa application with Build Configuration "Debug", it linked
with no errors but upon running the app quit immediately with this console
message:


ZeroLink: unknown symbol
'__Z48ParseArrayOfCommandLineArgumentsForLetterCommandP7NSArrayP8NSStri ng'


If instead I linked it with Build Configuration "Deployment", I got a bunch
of "Undefined symbol" errors during linking. It looked like I got an error
for each plain-old C function such as "void MyFunction(int someArg)" which
was called in one file but defined in another file.


I discovered hat the problem was only occurring if one of the files had the
.mm extension instead of .m. (This project was born as Objective-C++).
Removing .mm files, changing all .mm extentions to .m, and re-adding the
files fixed the problem.


Is this a bug, a feature, or another CodeWarrior exit exam which I have
failed?  (It links fine with the .mm extensions in CodeWarrior.)

It isn't a bug, but I'm not sure which of the other two it is. Chances are your .mm file was #include'ing a header which declared a function like this:
void ParseArrayOfCommandLineArgumentsForLetterCommand(NSArray *array, NSString *str);
When the .mm file was compiled, the declaration was compiled as C++, resulting in the name mangling above. That would've worked fine if the function was defined in a C++ file, but apparently it isn't. Since it's defined as a C function, you'd get this to work by telling the compiler that this is a declaration for a C function. You do that by surrounding your declarations with 'extern "C"', like this:


#ifdef __cplusplus
extern "C" {
#endif

void ParseArrayOfCommandLineArgumentsForLetterCommand(NSArray *array, NSString *str);
void DoSomethingElse(int foo);
etc.


#ifdef __cplusplus
}
#endif

The other solution is to do what you did and rename your file to avoid the C++ compiler. :)

Hope this helps,
Eric

_______________________________________________
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: 
 >Solved: "C" Functions Won't Link Between .mm Files (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Solved: "C" Functions Won't Link Between .mm Files
  • Next by Date: Re: Xcode-users Digest, Vol 2, Issue 726
  • Previous by thread: Re: Solved: "C" Functions Won't Link Between .mm Files
  • Next by thread: Re: Solved: "C" Functions Won't Link Between .mm Files
  • Index(es):
    • Date
    • Thread