Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

macos

gcc

qt

openmp

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 Studio-Qt environment.

Many thanks in advance!

like image 225
RHeged Avatar asked Jun 06 '11 13:06

RHeged


2 Answers

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’.

like image 55
bgp2000 Avatar answered Oct 17 '22 20:10

bgp2000


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.

like image 21
Joe Boo Avatar answered Oct 17 '22 21:10

Joe Boo