iOS applications cannot link with the static library or framework without specifying a minimum deployment target

Originator:kishikawakatsumi
Number:rdar://21724015 Date Originated:08-Jul-2015 11:12 PM
Status:Closed Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
If do not specify a minimum deployment target, iOS applications are not possible to link with the static library or framework.

This means that platform-independent code is not able to link with both iOS and watchOS. So we cannot make fat binary that works on both iOS and watch OS.

In Xcode 6, iOS applications were able to link even if there is no specified minimum deployment target by the `-mios-version-min = * version *` or `-miphoneos-version-min = * version *`.

This means that platform-independent code was able to link with both iOS and MacOS X in Xcode 6.

However, in Xcode 7, the library does not specify the minimum deployment target that it was no longer able to link with iOS apps due to following error:

```
ld: in /Users/katsumi/Desktop/Test/libtest.a(test-iPhoneSimulator.o), building for watchOS simulator, but linking in object file built for OSX, for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

Steps to Reproduce:
1. Create test.hpp and test.cpp, then write following code:

```
// test.hpp
#ifndef test_cpp
#define test_cpp

#include <stdio.h>

class Sample {
public:
    void test();
};

#endif /* test_cpp */
```

```
// test.cpp
#include "test.hpp"
#include <stdio.h>

void Sample::test(){
    printf("Sample::test was called\n");
}
```

2. Compile the above source file with following command:

```
clang -O3 -DNDEBUG -pthread -std=c++11 -I.. -Wall -Wextra -pedantic -DREALM_HAVE_CONFIG -stdlib=libc++ -arch armv7 -arch armv7s -arch arm64 -mstrict-align -isysroot '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk' -MMD -MP -c test.cpp -o test-iPhoneOS.o

clang -O3 -DNDEBUG -pthread -std=c++11 -I.. -Wall -Wextra -pedantic -DREALM_HAVE_CONFIG -stdlib=libc++ -arch i386 -arch x86_64 -isysroot '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk' -MMD -MP -c test.cpp -o test-iPhoneSimulator.o
```

This makes `test-iPhoneOS.o` and `test-iPhoneSimulator.o`

3. Create static libraries for each architecture with following command:

```
ar csr libtest-iPhoneOS.a test-iPhoneOS.o
ar csr libtest-iPhoneSimulator.a test-iPhoneSimulator.o
```

This makes `libtest-iPhoneOS.a` and `libtest-iPhoneSimulator.a`

4. Create fat binary with following command:

```
xcrun lipo libtest-*.a -create -output libtest.a
```

5. Make iOS application project with Xcode 7, and configure build settings to link with the above libraries

If you try to build for the simulator will fail with the error below:

```
ld: in /Users/katsumi/Desktop/LinkTest/libtest.a(test-iPhoneSimulator.o), building for iOS simulator, but linking in object file built for OSX, for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```


Expected Results:
To be able to link, it can run without problems.

Actual Results:
It fails to link with the error below:

```
ld: in /Users/katsumi/Desktop/LinkTest/libtest.a(test-iPhoneSimulator.o), building for iOS simulator, but linking in object file built for OSX, for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

Version:
OS X 10.10.3 (14D136), Version 7.0 beta (7A121l)
OS X 10.11 (15A204h), Version 7.0 beta (7A120f)

Notes:
In Xcode 6, the above library can link with applications for iOS simulator without error. It can link even with the application for OS X because it has same architecture and uses only platform independent API.

Our goal is to make the Fat binary that runs on both iOS and watchOS. But it is impossible for this problem. 

Configuration:
MacBookPro10,1, 16GB RAM
MacBook8,1, 8GB RAM

Attachments:

Comments

Apple Developer Relations 11-Jul-2015 05:30 AM

There are no plans to address this based on the following:

You want one slice of the binary to be watchOS and the other to be iOS. E.g., v7k watchOS and armv7+arm64 iOS. Then when linking, the right one gets pulled out, similar to having a fat library contain both a simulator and a device slice.

This is not something we want to support.

We are now closing this report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

By kishikawakatsumi at July 13, 2015, 9:17 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!