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

Re: .m to .mm causes missing function pointers


  • Subject: Re: .m to .mm causes missing function pointers
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 9 Jul 2007 07:43:18 -0700

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


  • Follow-Ups:
    • [SOLVED] Re: .m to .mm causes missing function pointers
      • From: David Farmer <email@hidden>
References: 
 >.m to .mm causes missing function pointers (From: David Farmer <email@hidden>)

  • Prev by Date: Re: [coredata] populate NSPopupButton with NSAttributedStrings
  • Next by Date: Re: NSImage representations
  • Previous by thread: .m to .mm causes missing function pointers
  • Next by thread: [SOLVED] Re: .m to .mm causes missing function pointers
  • Index(es):
    • Date
    • Thread