Link Intel Library to Generate Intel Binary on M1 Mac with Xcode - c++

I have 16" M1 Pro MacBook Pro. The third party C library (.a) was built with Intel Mac and there's absolutely no way to modify the code or rebuild with M1 Mac. The binary is x64 binary.
My project is using C++ and Objective-C++ (.mm) with Xcode. It is targeted for Mac app and not iOS. I want to link the C library to my project.
The linked library 'libkfunc64.a' is missing one or more architectures
required by this target: arm64.
I checked similar question but it didn't work:
Can Xcode on m1 Mac build targeting Intel
What I want to do is to generate an Intel binary. I don't need a M1 binary or hybrid binary - I can run Intel binary on Rosetta 2 on M1 Mac.
I created a console-app with "-arch x86_64" option for LLVM C++ compiler and it worked. But I don't know how to pass that option on Xcode.
Please tell me how to do it. I am using Xcode 13.3.

Xcode - Targets - Build Settings
Architectures (x86_64) or Excluded Architectures(arm64).
I've only tested the opposite.
Arm64 required, no x86_64.

Related

How to make Qt Creator use Rosetta and x86 compiler on Mac M1?

I am using Qt 5.15.2 on my Mac mini with M1 chip. This works fine (due to Rosetta). Below is the list of compilers Qt Creator found on this computer, and among them is the C++, x86 64bit that I use. No problem.
I would like to use the same settings on a (somewhat newer) Mac Book Pro (also with M1 chip). Below is the list of compilers Qt Creator finds on this computer, the x86 is now missing!
I do not know if I have a x86 compiler on the new M1-computer. I have installed Xcode and the command line tools for XCode 13.2.
Can I somewhere tell Qt Creator that the deployment target is x86?
Does /usr/bin/clang++ only compile for the ARM/M1-chip, or can it also produce and link to x86 code?
if not, how can I find out if there is an x86 compiler on my new M1-computer?
If the compiler is missing, how to install it?
Any help would be most appreciated!
A few tips that can help, I just setup a project using Qt 5.15.2 on a 2021 M1 Mac.
Note this will likely be different for Qt >= 6.
Can I somewhere tell Qt Creator that the deployment target is x86?
Yes, you can do this using specific argument in the build settings of your kit.
Add the QMAKE_APPLE_DEVICE_ARCHS="x86_64" additional argument to qmake.
Also, add an additional CMake option: -DCMAKE_OSX_ARCHITECTURES:STRING="x86_64"
ℹ️ Click Manage Kits.. in the projects view to open the preferences editor where you can update your CMake configuration.
Does /usr/bin/clang++ only compile for the ARM/M1-chip, or can it also produce and link to x86 code?
With rosetta installed (/usr/sbin/softwareupdate –install-rosetta –agree-to-license), and the configuration above, yes you can compile and link x86 binaries.

No compiler can produce code for this Qt version - Apple silicon

I am trying to port a linux project to macOS. However I can't even setup the build environment on an M1 Macbook Air 2020 (Apple silicon). I installed qt-creator, cmake, qt 5.15 and 6.1 using homebrew. I added the qt versions and cmake in the qt-creator settings. When I want to put everything together in the kits tab, I get the error in the title.
Checking the compilers tab, I realized that the autodetected clang compilers are x86 only. So I cloned the x86 clang++ entry and changed the ABI from x64 to arm. This should work I though, since clang++ is a unversial binary as file /usr/bin/clang++ reports
/usr/bin/clang++: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/clang++ (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/clang++ (for architecture arm64e): Mach-O 64-bit executable arm64e
What do I have to do to make Qt Creator able to build universal binaries? Or at least any build at all?
You need to install Qt 6.2 version which brings support for macOS on Apple Silicon. Porting tasks were tracked under this bug report. Currently, Qt5 doesn't support building for M1 chip.
In addition to updating to Qt6.2 you also need to update your Qt Creator version to Qt Creator 6. Alternatively, you can try the build flags below with Qt Creator 5.
As Qt Creator 5 is built as a non-universal binary, it will default to producing x86_64 binaries, regardless of which architecture your machine is. To build for arm64, add -DCMAKE_OSX_ARCHITECTURES=arm64 explicitly to the "Initial CMake parameters" of the project build settings, or QMAKE_APPLE_DEVICE_ARCHS=arm64 to the qmake "Additional arguments" field.

Qt 5.12.0 MinGW 7.3 w64 cross compile from windows 64 to windows x86

I have recently updated Qt to v 5.12.0. This version includes MinGW 7.3 W64 and there is not option to download MinGW 7.3 W32 as in previous version of Qt (see image below).
I've built my application using QtCreator 4.8.1, and it was built without issues, however I noticed that my binary file is in 64 bits, and not in 32 bits like in previous version of Qt.
My problem is that I want to build my application for x86 platforms, but I can't find any options in Qt to do that. How can I cross compile my app for x86 using MinGW 7.3 w64 and QtCreator?
FYI: My OS is Windows 10 x64.
It is possible to download the 32-bit version of mingw-64 separately
sourceforge.net
After that you should configure your Qt Kits in Qt Creator.

C++ Eclipse: Build a MacOSX App under Linux?

I have a C++ command line project using Eclipse under fedora
(Eclipse IDE for C/C++ Developers Oxygen.2 Release (4.7.2)).
Now i want to port this to the Mac.
To my surprise in the project settings of eclipse, in the list of available tool chains i found the entry "MacOSX GCC":
which contains a MacOS X C++ Linker. So i switched the used toolchain to this and rebuilt. The resulting file can still be executed under linux but its not executable when moved to a mac. It differs though slightly in size from the version built with the Linux GCC toolchain, but sill it is a linux, not a mac executable.
Question:
Can the MacOS X toolchain be used anyhow in the linux environment or
is this rather a bug?
If yes: What do i have to do, to build a MacOS X application under linux?

SFML 2.1 Code::Blocks Static linking not working,

I am new to the idea of linking libraries in c++, and am trying to get SFML to work with C++. I am on Windows 7 64-bit and am using Code Blocks. I have downloaded the 32-bit mingw GCC SFML DW2 version of SFML. I followed this tutorial: http://www.sfml-dev.org/tutorials/2.0/start-cb.php to set up code blocks. I am staticly linking the libraries. When I press the "Build" button, I get whole host of errors, with undefined reference to '__Unwind_Resume' and '__gxx_personality_v0'. I have looked up this issue, and have only found command line fixes, using g++ instead of gcc. I cannot do this within the codeblocks UI. Can someone give me a hand?
The version of the compiler shipped with code::blocks is the 32-bit 4.7 TDM-SJLJ one, so you need the version of SFML compiled with the same compiler (GCC 4.7 TDM (SJLJ) - 32 bits)
If you want to use the 64-bit version of the library you need to install the 64-bit version of the compiler, available here
change the linker program in settings->compiler->toolchains to g++.exe or mingw-g++.exe