iosobjective-ccocoapodsobjective-c++

"pod lib lint" command throws error with mixed objective-c and objective-c++ files


I try to create a simple cocoapods library with objective-c and objective-c++ files. When executing the command pod lib lint I get an error.

Pod structure:

Executing the command `pod lib lint --platforms=ios --verbose` on an M1 mac throws an error:

    Undefined symbols for architecture arm64:
      "_getValue", referenced from:
          _bar in foo.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    ** BUILD FAILED **

Does somebody know what's the problem?


Solution

  • When importing the sames headers into C++ and Objective-C compilation units, you have to wrap the declarations with extern "C" guards to avoid their names being mangled when linking:

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    int getValue(void);
    
    #ifdef __cplusplus
    }
    #endif