最新版本的GCC(4.6)如何在Mac OS下与Qt一起使用?

发布于 2024-11-14 05:42:12 字数 704 浏览 2 评论 0原文

我的问题与此处讨论的问题有关:

OpenMP 是否可以在 Qt 跨线程上运行?

在尝试在辅助线程中具有 OpenMP 子句的 Mac OS 下运行我的基于 Qt 的程序时,它崩溃了。浏览网页后,现在我明白这是由Apple提供的相当旧的gcc版本(4.2)中的一个错误引起的。

然后我从 http://hpc.sourceforge.net 下载了最新的 4.6 版本的 gcc 并尝试编译项目,但我从 g++ 编译器收到以下错误:

无法识别的选项“-arch” unrecognized option '-Xarch_x86_64'

我了解到这是因为这些选项只能由自定义配置的 Apple-gcc 编译器解释,而不能由标准 gcc 解释。

有人可以帮我解决这个问题并配置 g++ 4.6 与 Qt 一起使用以获得无错误的 OpenMP 支持吗?我承认我是 Mac OS 平台下编译器和编程方面的新手,并且想从 Visual Studio-Qt 环境移植我的代码。

非常感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

榆西 2024-11-21 05:42:12

如果您不怕弄乱 Qt 安装,请更改 ~/QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf 中的 QMAKE_CFLAGS_X86_64 条目。

将“-Xarch_x86_64”替换为“-arch x86_64”。

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

〃安静 2024-11-21 05:42:12

您可以使用非 Apple gcc v4.6 并为您想要构建的每个架构编译二进制文件(对于 i386 和 x86_64 使用 --target=${ARCH} 应该没问题)。然后,一旦你有了每个架构的二进制文件,就可以像这样使用 lipo:
lipo -create -arch i386 binary_32bit -arch x86_64 binary_64bit -output binary_universal
这将从binary_32bit和binary_64bit创建一个名为binary_universal的胖二进制文件(又名通用二进制文件)。

或者您可以使用 clang/llvm 而不是 gcc,它可能不会有您描述的错误,并且(如果通过 Apple 的开发人员工具提供)应该能够直接编译通用二进制文件。

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.

饮湿 2024-11-21 05:42:12

您应该运行带有相应 -spec 选项的 qmake,例如,要在 freebsd 上使用 gcc46,需要运行 qmake,如下所示:
qmake --spec=freebsd-g++46

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

你的呼吸 2024-11-21 05:42:12

Lipo 确实可以用来将多个目标文件放在一起成为一个“胖”目标文件,事实上这正是苹果编译器所做的。他们的 GCC 编译器实际上是一个驱动程序,它将各种体系结构映射到该体系结构的适当编译器,然后使用 lipo 将对象混合在一起。

请参阅: http://lists.macosforge.org/pipermail/macports -dev/2011-September/016210.html

这是该驱动程序的源文件:

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

要获得新版本的 GCC 来支持 -arch 标志,需要做的就是修改此驱动程序并使其指向您的 gcc 版本的脚本包装器,该脚本包装器为您的 gcc 版本添加适当的标志给定的架构,然后传递所有其余的参数。像这样的东西:

#!/bin/sh

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

#!/bin/sh

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

这里是一个讨论如何做到这一点的链接,并提供了一个 cmake 项目,可以轻松修复 GCC 的 macports 版本并支持两种英特尔架构的 -arch 标志:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文