Linker error using extern “C” in Objective-C code

前端 未结 2 1770
醉酒成梦
醉酒成梦 2021-01-06 09:55

I\'m trying to create some utility functions that can be called from both Objective-C and C++ code in an iPhone application. I have third party C++ classes that cannot be c

相关标签:
2条回答
  • 2021-01-06 10:32

    Double check your architecture - the issue from the linker is that it isn't compiling your .c file, not that it can't figure out the linkage. So here's what happens...

    Compiler goes through, can't find a way to compile the .c file properly Linker sees external C linkage, says "okay let's see if we can find it" can't find it because the .c file isn't compiled into object code, oh crap, abort.

    You need to check your build phase - so go to your targets, select whatever target is active, see what is happening in the compile phase - my guess is that somehow whatever target you're aiming for (release or debug) got this file added as a i386 target instead of arm, which is why it's confused and can't find a rule to compile it (you aren't targeting i386 so it doesn't have rules to compile it).

    If all else fails, try making a brand new target for arm and see if you can use it that way, or switch targets from release to debug, etc.

    If you show me a snapshot of whatever target you're compiling for I can probably be a lot more helpful :). Good luck!

    0 讨论(0)
  • 2021-01-06 10:35

    use the following construct to specify c linkage for c and c++ translations:

    #if !defined(__cplusplus)
    #define MONExternC extern
    #else
    #define MONExternC extern "C"
    #endif
    // declare loadMeshFromFile
    MONExternC void loadMeshFromFile(char const*, void*);
    

    this declaration will be compatible with c, objc, c++, objc++.

    0 讨论(0)
提交回复
热议问题