Maxim Krylov
Maxim Krylov

Reputation: 21

Linking error for mixed macOs app with static libs (swift, objc, c++)

I have two static libraries and one macOs App (all under latest XCode 8.1).

1) First lib (A), is ObjC++ (mixed objc and c++/stl)

2) Second (B) is pure ObjC, and contains some common categories (for NSObject for example)

3) The App is Swift and use both libs

All targets builds with the same c++ flags (libc++11 and so on), the problem is:

1) if I add -ObjC (and/or) -load_all linker flags to the App (to normal linkage with lib B categories), then i got many "Undefined symbols for architecture x86_64" (all about STL)

2) if i remove this linker flags, then App compile normal, but in runtime i'v got "missing selector" for all lib B categories.

However, if i completely remove lib B (adding all of its sources directly in the App) and respectively remove -ObjC/-load_all, then the problem with the STL linking is solved, but unfortunately this is not the right option for me. So I hope for your help, or at least an explanation of.

Thanks!

Upvotes: 1

Views: 170

Answers (1)

Anatoli P
Anatoli P

Reputation: 4891

Append -lc++ (standard C++ lib) to Other Linker Flags in Build Settings of your app and see if that solves the problem. Without knowing more about your app and libs, I'm not sure what's going on, but I would speculate that when -ObjC is added, causing additional code from libB to be loaded, then some symbols from the standard C++ library are somehow needed, but not available.

Alternatively you can add libc++.tbd in the Link Binary With Libraries section in the Build Phases of the app. It's available in the frameworks and libraries list that comes up when you click the + sign in that section.

Upvotes: 1

Related Questions