LNI
LNI

Reputation: 3181

Using C++ inside an iOS CocoaPod

I am building a private cocoapod for iOS, and am running into issues with some C++ code. The project builds fine in XCode, but when I attempt to run pod lib lint MyProjectName.podspec I get the following error:

- ERROR | xcodebuild: /path/to/aheader.h:2:10: error: 'string' file not found

The header has the following first line:

#include <string>

Searching for possible solutions, I added the following to podspec (based on CocoaPods: Linking with C++ symbols defined in libPods.a)

s.source_files = "MyProjectName/**/*.{swift,c,m,h,mm,cpp,plist}"
s.library = 'c++'
s.xcconfig = {
   'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
   'CLANG_CXX_LIBRARY' => 'libc++'
}

But it made no difference to the error. Another suggestion I saw was to "use a wrapper", but this piece of code (which is 3rd-party IP that I can not port to Objective C) is already using a wrapper.

How can I build the pod successfully by mixing both Objective C and C++ along with Swift? Any (non-null) pointers would be appreciated.

Upvotes: 5

Views: 2474

Answers (2)

Nathan
Nathan

Reputation: 12313

Try explicitly adding stdc++ in the linker options.

  s.pod_target_xcconfig = {
    'OTHER_LDFLAGS' => '-l"stdc++"'
  }

Upvotes: 0

LNI
LNI

Reputation: 3181

I had to simply renamed the C++ header extension to .hpp, so it was not included by default in the source_files filter. This resolved the issue, as the wrapper was including the header. Posting this in case someone else runs into the same issue.

Update: Nope, it just lets the app build, but using the pod still doesn't work.

Upvotes: 2

Related Questions