如何在macOS的Qt中使用OpenMP进行编译? [英] How to compile with OpenMP in Qt on macOS?
问题描述
我正在尝试在我的C ++ Qt应用程序中引入一些OMP并行化,但是我无法在macOS下对其进行编译.同事们正在使用Windows或Linux,并且一切工作正常.我需要在Qt的.pro文件中写什么,并在系统中做什么?
I'm trying to introduce some OMP parallelization into my C++ Qt application and I'm failing to compile it under macOS. Colleagues are using Windows or Linux and everything is working fine for them. What do I need to write in Qt's .pro-file and do in my system?
此站点或任何其他站点上的类似问题均未解决我的问题.我通常使用Apple提供的clang进行编译,但似乎对此没有OMP支持.因此,我通过自制软件在llvm中安装了clang,相应地在Qt中设置了我的工具包,还尝试了.pro文件中以下各行的所有排列:
None of the similar questions on this or any other site solved my problem. I'm usually compiling with Apple-provided clang, but there seems to be no OMP-support for that. So I've installed clang with llvm via homebrew, set up my kit in Qt accordingly and also tried every permutation of following lines in my .pro-file:
QMAKE_CXXFLAGS += -fopenmp
QMAKE_LFLAGS += -fopenmp
QMAKE_LINK = /usr/local/Cellar/llvm/9.0.0/bin/clang-9
QMAKE_CC = /usr/local/Cellar/llvm/9.0.0/bin/clang-9
QMAKE_CXX = /usr/local/Cellar/llvm/9.0.0/bin/clang-9
LIBS += -fopenmp
LIBS += -L/usr/local/lib/
所有这些,我遇到许多奇怪的问题,导致没有为x86_64体系结构找到符号
,也没有指向clang-9的任何行,但这仍然是我最好的可以实现.没有最后一行,我会得到-lomp 找不到的库,没有QMAKE_LINK行
.不支持的选项'-fopenmp'
的
With all of that I get many weird problems leading to symbol(s) not found for architecture x86_64
, also without any of the lines pointing to clang-9, but still this is the best I could achieve.
Without the last line I get library not found for -lomp
, without the QMAKE_LINK line unsupported option '-fopenmp'
.
对于这些错误消息,我在网上发现的所有可能解决方案均无济于事. libomp.dylib
已安装并链接到/usr/local/lib
.我还在GCC上尝试了整个过程,但也没有成功.
None of the possible solutions I found online for these error messages helped either.
libomp.dylib
is installed and linked into /usr/local/lib
.
I also tried the whole process with GCC, but without success as well.
这已经困扰了我三天,我真的希望可以解决这个问题.可以这么难吗,可以吗?不影响 Windows/Linux 兼容性的解决方案将是最佳选择.
This is bugging me for three days already and I really hope this can be solved. Can't be that hard, can it? A solution that isn't messing with the compatibility on Windows/Linux would be optimal.
PS:我正在通过Qt Creator中的播放按钮使用qmake.
PS: I'm using qmake via the play button in Qt creator.
Reference: 1, 2, 3, 4 and many others.
推荐答案
AppleClang应该可以正常工作.确保通过 .pro
文件调用预处理器来处理OMP.
AppleClang should work just fine. Be sure to call the preprocessor to handle OMP via the .pro
file.
macx: {
QMAKE_CXXFLAGS += -Xpreprocessor -fopenmp -lomp -I/usr/local/include
}
macx: {
QMAKE_LFLAGS += -lomp
}
macx: {
LIBS += -L /usr/local/lib /usr/local/lib/libomp.dylib
}
这篇关于如何在macOS的Qt中使用OpenMP进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!