Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 543761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:35:04+00:00 2026-05-13T10:35:04+00:00

I am trying to figure out why when I convert my main.m file to

  • 0

I am trying to figure out why when I convert my main.m file to a main.mm file, it no longer will link properly.

I have reduces the problem to the following example code:

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main( int argc, const char ** argv ) {
return NSApplicationMain( argc, argv);
}

I am using gnustep and linux. I enter the following commands and everything works as expected:

g++ -g -c main.m -I/usr/GNUstep/Local/Library/Headers -I/usr/GNUstep/System/Library/Headers

g++ -g -o test main.o -L/usr/GNUstep/Local/Library/Libraries -L/usr/GNUstep/System/Library/Libraries -lgnustep-base -lgnustep-gui

Now if I rename main.m to main.mm and use these two commands ( same exept main.m now main.mm):

g++ -g -c main.mm -I/usr/GNUstep/Local/Library/Headers -I/usr/GNUstep/System/Library/Headers

g++ -g -o test main.o -L/usr/GNUstep/Local/Library/Libraries -L/usr/GNUstep/System/Library/Libraries -lgnustep-base -lgnustep-gui

I get the following error:
main.mm:7: undefined reference to `NSApplicationMain(int, char const**)’

Can someone please find what I am doing wrong? I do not see why it is now failing to link.

I am trying to add some C++ classes to an objective c program and this is preventing me from continuing.

Thank you for any help you can provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:35:04+00:00Added an answer on May 13, 2026 at 10:35 am

    The problem is that when you compile it as C++, the compiler mangles the name of the symbol NSApplicationMain, so it can’t find it, since it’s looking for something like __Z17NSApplicationMainiPPKc. You can use the nm program (from binutils) to see what symbols the object files are referencing:

    $ # When compiled as Objective-C:
    $ nm main.o | grep NSApplicationMain
                     U NSApplicationMain
    $ # When compiled as Objective-C++:
    $ nm main.o | grep NSApplicationMain
                     U _Z17NSApplicationMainiPPKc
    

    In order to avoid this problem, C functions need to be declared with an extern "C" modifier in order to tell the compiler not to mangle the name. Looking into <AppKit/NSApplication.h>, the header file where NSApplicationMain is declared, I see this:

    APPKIT_EXPORT int
    NSApplicationMain(int argc, const char **argv);
    

    Alas, APPKIT_EXPORT is defined to be one of extern, __declspec(dllexport), extern __declspec(dllexport), or nothing in <AppKit/AppKitDefines.h>. Since it’s also used for global variable declarations, we can’t get around this by redefining it to extern "C" (which would be extremely hacky and kludgy anyways). The AppKit header files do not seem to contain any extern "C" declarations at all, although I do see them in various header files under Foundation/ and GNUStepBase/.

    So what can you do? The solution is to wrap your includes with an extern "C":

    extern "C"
    {
    #import <Foundation/Foundation.h>
    #import <AppKit/AppKit.h>
    }
    
    int main( int argc, const char ** argv ) {
      return NSApplicationMain( argc, argv);
    }
    

    This will give the functions defined in those header files the proper linkage, and it will all work out. But you shouldn’t have to do this — I would file a bug report with GNUstep, telling them to add proper extern "C" declarations to their header files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to convert the following SQL statement to Entity
I have this query that i've been trying to figure out how to convert
Trying to figure out how to convert how to covert 5 variables I have
Hey I'm trying to figure out how to convert a statement that works in
I was looking at the ImageConverter class, trying to figure out how to convert
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text
Trying to figure out why File Attachment isn't showing on a custom content type.
I have two databses, tempdblog and testdblog. I'm trying to figure out how, when
I'm trying to figure out how difficult it would be to convert a Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.