Thick newbie migrating to xcode from MS. Link errors

Discussion in 'iOS Programming' started by JEDev, Sep 30, 2010.

  1. JEDev macrumors newbie

    Joined:
    Sep 30, 2010
    #1
    Hi all

    This is a thickie question (it is late and I am tired). I am just starting with xcode and obj-c. Running tutorials etc but as I am coming over from "the other side" I cannot help but think I am missing something here.

    I have some basic c fns defined in a .mm file.
    I have the declarations in a .h file
    The .h is #imported into a view.m obj-c file.
    but I get a build error of the symbol from the .mm not being found.

    Hopefully the screenshot shows all (the coding is just hacking through sample projects to see how it all glues together..)

    [​IMG]

    A pointer to good xcode resource / pdf would be great... one of the hardest things I ting to moving to a new environment is finding the doco

    Thx
    J
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    A .mm file is compiled as Objective-C++.
    A .m file is compiled as Objective-C.

    You can't link these two things together, unless the Objective-C++ code contains the extern "C" { ... } blah-blah around the C-style functions.

    If this was taking precisely from a tutorial, then double-check you named files correctly. If the tutorial really says to mix .m and .mm, then post the URL of the tutorial.

    Unless you absolutely need to use Objective-C++ (and from the posted code, you don't), one remedy is to change the .mm to a .m file. Then everything is one language: Objective-C.

    This is exactly the same as compiling a .cpp file containing C-style functions, which you then try to call from a C program in a .c file. Because C++ performs name-mangling, the function names won't link up.
    http://en.wikipedia.org/wiki/Compatibility_of_C_and_C++#Linking_C_and_C.2B.2B_code
     
  3. JEDev thread starter macrumors newbie

    Joined:
    Sep 30, 2010

Share This Page