building for OSX, but linking in object file built for iOS

Hi.


I'm trying to build some software written in C on a Mac (a Mac Mini to be specific) such that the software can be used with iOS running on an ARM chip. The Mac is running OS X v10.10.5, and it has Xcode v7.2.1 installed.


Building the software as static libraries seems to work fine. But when the build tried to build dynamic libraries, I saw this error:


ld: library not found for -ldylib1.10.5.o

clang: error: linker command failed with exit code 1 (use -v to see invocation)


The build is specifying an -isysroot qualifier with this as the value:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk


There is a file named dylib1.10.5.o in this directory:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib


But there is no such file in what I guess would be the corresponding directory for the iPhone:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib


In both directories there is a file named simply dylib1.o. In the first directory above this dylib1.o file is the same size as the dylib1.10.5.o file. In the iPhone directory I copied dylib1.o to dylib1.10.5.o, and this seems to have gotten me past the error (and on to the next one).


I then ran into a similar error saying "library not found -lgcc_s.10.5". In this case I copied the file libgcc_s.1.tbd to libgccs_10.5.tbd in the iPhone directory.


These two copies seem to have gotten me past the "library not found" errors. Although I'm not certain if those two file copies that I did are advisable.


But now I'm getting this:


ld: building for OSX, but linking in object file built for iOS, file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/dylib1.10.5.o' for architecture armv7


The problem is I don't want to build for OS X; I want to build for iOS.


Here's the invocation of the command to link the dynamic library (slightly redacted):

/usr/bin/gcc -arch armv7 -mthumb -dynamiclib -fPIC -fno-common -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -o ../lib/lib<name>.dylib ./<obj 1>.o ./<obj 2>.o ./<obj 3>.o -L../lib -lm -lpthread


If I look at the .o files with the "file" command, it reports that they're ARM files, which is what I want. But apparently they're built for OS X on ARM instead of iOS on ARM.


What am I missing? Is the problem that I'm invoking /usr/bin/gcc instead of a different tool chain? There doesn't seem to be an alternative in Xcode iPhoeOS hierarchy. How can I obtain the correct gcc?

This is not entirely clear. You're using Xcode 7.2.1, but what are you using it for? Do you have a target in Xcode that you're building? In that case, the problem is that you have a macOS target rather than an iOS target.


But then why are you invoking /usr/bin/gcc, via the command line, I presume? So you're not compiling within Xcode, just using it as a text editor? In that case, I think there's a linker option that says what platform you're linking for, which (as you don't seem to have specified) defaults to macOS.


Perhaps you should try creating an entire iOS app within Xcode (with trivial code, but main target and dynamic library) and look at the compile and link command line options shown in the build transcript.


Finally, my recollection of the timing is hazy, but iOS frameworks are relatively recent. Are you sure that the tools in Xcode 7 are actually capable of building an iOS dylib?

I'm not actually using Xcode for anything. It's there because it supposedly has the pieces to do this build. The build simply uses makefiles that invoke a gcc binary.


This Mac was recently upgraded to OS X v10.10.5 from an older version (I forget what it was) by a contractor. Prior to the upgrade, we had a configuration that worked for doing this build. The configuration had everything in the /Developer hierarchy, which the contractor says is the hierarchy that Xcode used to create. So, to your question about whether Xcode 7 can build an iOS dylib, I would think it can, since whatever older version of Xcode we had before was able to do it.


I can copy the old /Developer hierarchy from the backup to the main disk, but with the newer version of OS X it no longer works. The contractor suggested installing Xcode v7.2.1, which is the newest Xcode that can be used with OS X v10.10.5. We did the install, but where the old /Developer hierarchy had a gcc tool chain that was explicitly for iOS on ARM, the new /Applications/Xcode.app/Contents/Developer hierarchy doesn't have such a tool chain.


The contractor suggested just using /usr/bin/gcc, but that, as you can see, produces code for OS X on ARM, not iOS on ARM. The contractor pretty much admitted that issues like this are out of his area of expertise.


The previous configuration was put in place by someone who is no longer with our company, so now I have the task of trying to configure this Mac so this build will once again succeed. Unfortunately my knowledge of doing development work on the Mac is very limited.


The build procedures (makefiles) are the same as we used before with the previous configuration that worked, albeit with a couple of directories changed to match the new Xcode version. It seems that we're missing a gcc that is specifically designed for creating code for iOS on ARM.


So...how do we get that cross compiler tool chain? I noticed that there are .dmg files named DeveloperDiskImage.dmg in the iPhone directories within Xcode. Do I need to do something with one of those?


I did start the Xcode app (never used it before) and chose to create a new Xcode project. For iOS it presents me with a choice of Application or Framework & Library. For my purposes Framework & Library seems more appropriate. But then it gives me a choice between Cocoa Touch Framework and Cocoa Touch Static Library. I have no idea what either of those is.


And in regard to linker options, since you mentioned that, our linker options include -arch armv7 and -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk. But specifying these with /usr/bin/gcc results in code for OS X on ARM instead of iOS on ARM. The previous configuration specified both of these but used a gcc apparently specifically designed to create code for iOS on ARM.

OK, I understand, but I don't have a good answer for you. It gets complicated because Xcode has a different toolchain from the one you'll use if you run the tools in /usr/bin manually.


Assuming your organization is a registered Apple developer, you best choice might be to use a Tech Support Incident to get the help of an Apple engineer. (Go to your account page on developer.apple.com and navigate to the Code Level Support page.) It should be free, and you shouldn't have to wait for more than a couple of days. It seems to me you are asking the right questions, but only Apple can give you definitive answers.

building for OSX, but linking in object file built for iOS
 
 
Q