is static library with Objective C compatible with any version of XCode? - objective-c

I am from c++ background and in c++ world, if I create an static library with any specific version of a compiler, then it is advisable to use same version of compiler for binary which will use this static library.
Is this statement true for Objective C static library as well? or if I have Objective C static library compiled with XCode X & and executable compiled with XCode Y still there will be no conflict?

Yes no conflicts. Migration of my legacy project on Objective-C to Xcode 12 was done without problems: just opened and compiled. Despite my colleagues: they had to continue working with Xcode 10 and 11 on swift projects.
Objective-C is ABI, Module and Source stable language like C, despite C++ and Swift

Related

Swift Build Linux vs macOS <Foundation/Foundation.h> not found

I am trying to use an old Obj-C static library in a Swift package. I am able to get the package compiling successfully on my mac by using compiler flags in the swift build command. However when running on a Dockerfile running 5.1-xenial the header file's in the static library produce the following error:
#import <Foundation/Foundation.h> "Foundation.h" not found.
As I understand is the because Objective-C foundation library is not available on the machine ? Would I have to install something like GNUstep? Is Swift interoperable with Objective C (I saw that it might not be possible on another SO post) ?
Update on GNUStep approach:
I was able to install and run GNUStep allowing for Objective-C development tools (i.e the Linux Foundation framework) alongside Swift however during the swift build I end producing this error:
/usr/GNUstep/Local/Library/Headers/GNUstepBase/GSObjCRuntime.h:92:1: error: expected identifier or '('
#class NSArray;
^
I think this is because Swift build treats the header file as a purely C library. Any suggestions on fixing this problem ?

Objective-C and Swift ABI

I know there are still some ABI (Application Binary Interface) issues between different versions of Swift, and it can cause a framework built with one version of Swift to not usable by an application built with another version of Swift.
But I am not sure if Objective-C and Swift have such an issue. That is to say, can a framework built with Swift be consumed by any version of Objective-C, in the ABI context?

Why Can't I Compile Objective-C/C++ (.mm) Files with MacPorts gcc-mp-4.6?

I have a C++11 codebase I compile with gcc 4.6 from MacPorts on OS X Lion. I also need to compile and link some OS-specific Objective C/C++ files to make the final executable. I would like to use the same compiler version to compile the whole project, but I cannot get the MacPorts version 4.6 of gcc to recognize Objective-C files; it always attempts to interpret them as C++ code and ignores the .mm file extension. (Compiling these files does work with the Xcode version of gcc, just not the MacPorts one. However that gcc is version 4.2 and I want to compile everything with gcc 4.6 or later.)
Forget IDE's or build tools: I get the same result from a commandline invocation of the compiler. That is, I record a commandline that works for compiling .mm files with the Apple gcc, verify yes it does work from the commandline, then run the identical command with nothing changed but the compiler used and it doesn't work. What am I missing?
It appears maybe the specific problem I'm having might be due to an Apple specific language extension, as the specific error I get is the same as this quote from a blog post:
After adding this, I was good for about 30 seconds until I get to the
portion of my project where some COCOA Objective-C UI stuff was being
compiled.
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24:
error: expected unqualified-id before '^' token
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24:
error: expected ')' before '^' token
Uh oh. I know what this is. This is the Apple "blocks" language
extension. It appears that blocks are used in a bunch of the system
header files. I don't think there is going to be a way to get around
this using MacPorts gcc. The FSF gcc just doesn’t know about blocks.
Fortunately for me, I didn't have anything in the Objective C/C++ code
that needed to be compiled with gcc 4.6 so I just had this target
compile using clang.

Compiling Objective-C files into object files (.o)

I have been tasked to create object .o files for an iOS project in Xcode 4. I have tried the following command which works on NSObject classes
gcc -c implemtationfile.m
but if I try to run the command on a class inherited from UIViewController for example I get a ton of errors starting with
UIKit/UIKit.h: No such file or directory
Secondly, since there are multiple files in the project, is it possible to create one .o file for all source files?
Not surprised you've got errors.
You are trying to compile iOS code from OSX. If you invoke GCC from the terminal, you'll get the Mac OS X compiler.
Even if it can produce .o files, those object files are Mach-O object files, meaning they are compiled as object-files against the Mac OS X compiler tool-chain.
No iOS here. Your object files will have the Intel (x86) or PPC architecture. iPhone is ARM, so you're wasted.
You should be able to proceed ARM object files using the right GCC compiler tool-chain.
Something like:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.0.1
I haven't tested, but that's clear that you need to use the iPhone ARM version of GCC. Just invoking GCC will invoke the Mac OS X version (in /usr/bin/).
A compiler like GCC needs to be compiled for a host and a target architecture.
The host architecture is the architecture in which you will invoke the compiler.
The target one is the architecture for which you'll build binaries, or object files.
So try to compile your code with the correct version of GCC, which suits the iPhone target architecture.
Also note that, if compiling against a framework, you should use the -framework GCC argument.

Linking a lib written in C in XCode + Objective-C

Is it possible to use a library I wrote in C (compiled with GCC on a Mac) on an Objective-C project under XCode?
The project is for a Mac OS X app, not iOS. The library was compiled via GCC on the command line and it is in C (as in C language) and the header for the library (.h file) is a simple C header with function declarations.
If yes, how? Furthermore, do I need to convert the .h files to an objective-c styled header?
Thank you!
You might take a look at Using static libraries with iPhone SDK.