• 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
[SOLVED] Re: .m to .mm causes missing function pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: .m to .mm causes missing function pointers


  • Subject: [SOLVED] Re: .m to .mm causes missing function pointers
  • From: David Farmer <email@hidden>
  • Date: Mon, 9 Jul 2007 10:36:16 -0500

Thanks Chris!!!

that was it, I had encountered this but did not relate it to the current issue. now it has taken a place in the golden book of ObjC pages. 9-)

David Farmer
coreaudiovisual

On Jul 9, 2007, at 9:43 AM, Chris Hanson wrote:

On Jul 9, 2007, at 7:27 AM, David Farmer wrote:

I have added some ObjC sources ( using Cocoa frameworks ) to an iTunes Visual plugin. Everything worked great until I decided to convert the .m ( ObjC ) source into a .mm ( ObjC++ ) source. Now my ObjC functions for that source file can no longer be linked. They are missing. Just by renaming the source suffix to .mm.

C++ uses "name mangling" to implement function overloading. If a C+ + (or Objective-C++) compiler sees a function call, it will generate a call to a "mangled" version of the function's name that includes type information. You need to mark the function as having C linkage using the extern "C" construct when its declaration is seen by the compiler; this will let the compiler know not to mangle its name.


The common way to do this is to either write the declarations in your header files within an extern "C" block like this:

#ifdef __cplusplus
extern "C" {
#endif

void Function1(int foo);
long Function2(char *bar);

#ifdef __cplusplus
}
#endif

or to define your own MYAPP_EXTERN macro in some common header and then use it like this:

/* common header */
#ifdef __cplusplus
#define MYAPP_EXTERN extern "C"
#else
#define MYAPP_EXTERN extern
#endif

/* other headers that include common header */
MYAPP_EXTERN void Function1(int foo);
MYAPP_EXTERN long Function2(char *bar);

You can see by inspecting some of their headers that the Cocoa frameworks typically do the latter.

  -- Chris


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >.m to .mm causes missing function pointers (From: David Farmer <email@hidden>)
 >Re: .m to .mm causes missing function pointers (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Handling Multiple Document Types
  • Next by Date: Re: Multi-project solution in Xcode
  • Previous by thread: Re: .m to .mm causes missing function pointers
  • Next by thread: Path to desktop
  • Index(es):
    • Date
    • Thread