How a recent version of GCC (4.6) could be used together with Qt under Mac OS?

核能气质少年 提交于 2019-12-05 02:03:20

If you aren't afraid of messing with your Qt installation, then change the QMAKE_CFLAGS_X86_64 entry in ~/QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf.

Replace ‘-Xarch_x86_64’ with ‘-arch x86_64’.

You can use your non-Apple gcc v4.6 and compile a binary for each architecture you want to build (use --target=${ARCH} should be fine for i386 and x86_64). Then once you have a binary for each of the architectures use lipo like so: lipo -create -arch i386 binary_32bit -arch x86_64 binary_64bit -output binary_universal This will create a fat binary (aka universal binary) named binary_universal from binary_32bit and binary_64bit.

Or you could use clang/llvm instead of gcc, which probably won't have the bug you described and (if supplied via Apple's developer tools) should be able to compile universal binaries directly.

You should run qmake woth corresponding -spec option, for example, to use gcc46 on freebsd it is needed to run qmake so: qmake --spec=freebsd-g++46

Lipo can indeed be used to put multiple object files together into a "fat" object file, in fact it turns out this is just what apple's compiler does. Their GCC compiler is actually a driver that maps various architectures to the appropriate compiler for the architecture and then mashes the objects together using lipo.

see: http://lists.macosforge.org/pipermail/macports-dev/2011-September/016210.html

Here is the source file for that driver:

http://opensource.apple.com/source/gcc/gcc-5666.3/driverdriver.c

All one needs to do to get a new version of GCC to honor the -arch flag is to modify this driver and get it to point to a script wrapper for your version of gcc that adds the appropriate flags for the given architecture and then passes all the rest of the arguments. Something like this:

#!/bin/sh

/opt/local/bin/gcc-mp-4.6 -m32 $@

and

#!/bin/sh

/opt/local/bin/gcc-mp-4.6 -m64 $@

Here is a link that talks about how to do it, and provides a cmake project to easily get the macports version of GCC fixed up and supporting the -arch flag for the two intel architectures:

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!