0

I'm trying to fix our unit tests. The iOS app is complex, with a number of open-source libraries statically linked into the application binary, including Google protobuf and Boost. These are built as static-link libraries in separate targets in our iOS app Project, and linked into the main app.

Up until now, those libraries were also linked directly into the test target, even though the app hosts the testing. But I ran into an issue early in Google Protobuf initialization that makes me think the presence of that library both in the test target and in the main application target is a problem. So I removed the static libraries from the test target, thinking that the Objective-C++ methods that reference stuff in that library would still find it in the main app executable. This does not seem to be the case, as the linker is failing to link test files that reference C++ code defined in the static library linked into the application binary.

Objective-C and Swift code does seem to link correctly.

I'm not sure what to do to resolve this situation. As I understand Xcode unit testing, one normally does not include the code of the main application in the test target. But I'm not sure how to tell Xcode that my test files need to be able to link against arbitrary code in the app.

This is all in Xcode 10.1.

Rick
  • 3,298
  • 3
  • 29
  • 47

1 Answers1

0

It's not uncommon to have to link against the same libraries in both production code and test code. Imagine a library with a Foo object, used in production. Some tests will want to make a Foo. But they can't just grab it out of the app. The tests need to link against the library, too.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • I don't think that's the case. I've successfully linked it in a sample project. The problem with trying to link the static library in into my test target as well as the application target is that it attempts to instantiate some static stuff twice (protobuf), and that causes a failure. – Rick Apr 14 '19 at 01:58