开发者

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

开发者 https://www.devze.com 2023-03-10 23:10 出处:网络
My problem is related to the one discussed here: Is there a way that OpenMP can operate on Qt spanwed threads?

My problem is related to the one discussed here:

Is there a way that OpenMP can operate on Qt spanwed threads?

Upon trying to run my Qt-based program under Mac OS that has an OpenMP clause in a secondary thread, it crashed. After browsing through the web, now I understand that it is caused by a bug in the rather old version (4.2) of gcc supplied by Apple.

Then I downloaded the latest 4.6 version of gcc from http://hpc.sourceforge.net and tried to compile the project, but I got the following errors from g++ compiler:

unrecognized option ‘-arch’ unrecognized option ‘-Xarch_x86_64’

I learned that this is because these are options, which can be only interpreted by the custom-configured Apple-gcc compiler, but not by standard gcc.

Could anybody please help me could I overcome this issue and configure g++ 4.6 to use with Qt in order to get a bug-free OpenMP support? I admit that I'm a newbie under Mac OS platform with regard to compilers and programming and would like to port my code from Visual开发者_如何学Python Studio-Qt environment.

Many thanks in advance!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号