Building for iOS but linked library was built for MacOS

Hey guys,

I am trying to compile C++ code on Mac using command line tools(g++) to output a static library(.a). I compiled it with architecture support for arm64, however when I link it in Xcode project I get the following error

Building for iOS but linked library was built for MacOS

I have used following command

g++ -shared -o ./libCrossPiOS_TestMulti.iOS.a ./alpha.cpp -arch arm64

I understand that I can choose XCFrameworks route to get past this but wanted to understand what I'm missing in this approach.

Any help will be appreciated. Thanks in advance

Screenshot of error

The Unix-y command-line tools, clang and so on, default to targeting macOS. If you want to target another platform you need to tell them to do so. For Apple tools there’s an easy way to work out the relevant magic, namely to create a dummy test project in Xcode and then copy what it does. For third-party tools you’ll need to consult the vendor’s support resources.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Can you please help/guide me with how to change the default targeting as macOS to iOS?

I already did:

For Apple tools there’s an easy way to work out the relevant magic, namely to create a dummy test project in Xcode and then copy what it does.

Please try this out and post back if you have specific questions.

I can’t help you with third-party tools because DTS can’t possibly maintain expertise in all the third-party tools out there. If you’re using third-party tools, you should escalate this with the tool’s vendor.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Building for iOS but linked library was built for MacOS
 
 
Q