Cocoapods link_with XCTest generates duplicate symbol errors
-
20-12-2019 - |
Question
I have this main project that will generate a static library (call it MySDK
). I have a component (call it Analytics
) as a private cocoapod.
So I end up with a file structure like this:
+ MySDK
- src
+ Pods
+ Pods
- Analytics
Each project has it's own tests, but now I need to do some integration testing so in my Podfile I use link_with
, but whenever I do this I can't even run the original tests because I get a bunch of duplicate symbol
errors:
duplicate symbol _OBJC_METACLASS_$_PodsDummy_Pods in:
/.../DerivedData/Build/Products/Release-iphonesimulator/libPods.a(Pods-dummy.o)
/.../DerivedData/Build/Products/Release-iphonesimulator/libMySDK.a(Pods-dummy.o)
...
duplicate symbol _MYPREFIXFileTableIDColumnName in:
/.../DerivedData/Build/Products/Release-iphonesimulator/libPods.a(MYPREFIXDatabaseConstants.o)
/.../Build/Products/Release-iphonesimulator/libMySDK.a(MYPREFIXDatabaseConstants.o)
All the errors come from my Analytics
component. All the files causing a problem have C functions (I'm dealing with sqlite directly) and/or (global) constants, or they are categories, but they're all prefixed.
My Podfile
looks like this:
platform :ios, '7.0'
link_with ['MySDK', 'MySDKTests']
pod 'Analytics', '0.0.1'
My podscpec for Analytics
looks like this:
Pod::Spec.new do |s|
s.name = 'Analytics'
s.version = '0.0.1'
s.platform = :ios
s.summary = "Analytics utility"
s.homepage = 'http://google.com'
s.author = { 'Me' => 'me@me.com' }
s.source = { :git => 'https://github.com/Company/Analytics.git', :tag => '0.0.1' }
s.source_files = 'Analytics/**/*.{h,m}'
s.requires_arc = true
s.ios.deployment_target = '6.0'
end
Is there a reason why I'm getting these errors? Should I compile these files as non-arc or use some special flag?
Any ideas
Solution
I finally got it to work!
I shouldn't have linked my pods to MySDKTests
, since the final product (MySDK
, a library, was already linking against Analytics
).
I did however add the following to my podspec
file:
s.public_header_files = 'Analytics/**/*.h'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '"$(SRCROOT)/Pods/Headers/Analytics"' }
The second line is not really necessary because it's not modifying my MySDKTests
target. I did have to add HEADER_SEARCH_PATHS
to my MyDSKTests
to make those headers available to the tests.
I've read that some people successfully use LIBRARY_SEARCH_PATHS
instead, but this didn't work for me. If anyone care to explain why, that'd be great, but for now I'll leave my solution here for other people in case they come across similar issue.
See this other question for related info