Thick newbie migrating to xcode from MS. Link errors

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

  1. JEDev macrumors newbie

    Sep 30, 2010
    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..)


    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

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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.
  3. JEDev thread starter macrumors newbie

    Sep 30, 2010

Share This Page