简体   繁体   English

如何在 macOS 上的 Qt 中使用 OpenMP 进行编译?

[英]How to compile with OpenMP in Qt on macOS?

I'm trying to introduce some OMP parallelization into my C++ Qt application and I'm failing to compile it under macOS.我试图在我的 C++ Qt 应用程序中引入一些 OMP 并行化,但我无法在 macOS 下编译它。 Colleagues are using Windows or Linux and everything is working fine for them.同事们正在使用 Windows 或 Linux 并且对他们来说一切正常。 What do I need to write in Qt's.pro-file and do in my system?我需要在 Qt's.pro-file 中写什么并在我的系统中做什么?

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.我通常使用 Apple 提供的 clang 进行编译,但似乎没有 OMP 支持。 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:因此,我已经通过自制软件安装了带有 llvm 的 Z2C5517DB7DB7BC397F9B14AE357A7CE54FFZ,相应地在 Qt 中设置了我的套件,并且还尝试了 my.pro 文件中以下行的所有排列:

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/

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.有了所有这些,我遇到了许多奇怪的问题,导致symbol(s) not found for architecture x86_64 ,也没有任何指向 clang-9 的行,但这仍然是我能做到的最好的。 Without the last line I get library not found for -lomp , without the QMAKE_LINK line unsupported option '-fopenmp' .如果没有最后一行,我会得到library not found for -lomp ,没有 QMAKE_LINK line unsupported option '-fopenmp'

None of the possible solutions I found online for these error messages helped either.我在网上找到的这些错误消息的可能解决方案都没有帮助。 libomp.dylib is installed and linked into /usr/local/lib . libomp.dylib已安装并链接到/usr/local/lib I also tried the whole process with GCC, but without success as well.我还用 GCC 尝试了整个过程,但也没有成功。

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.不影响 Windows/Linux 兼容性的解决方案将是最佳解决方案。

PS: I'm using qmake via the play button in Qt creator. PS:我通过 Qt creator 中的播放按钮使用 qmake。

Reference: 1 , 2 , 3 , 4 and many others.参考: 1 , 2 , 3 , 4等等。

AppleClang should work just fine. AppleClang 应该可以正常工作。 Be sure to call the preprocessor to handle OMP via the .pro file.一定要通过.pro文件调用预处理器来处理 OMP。


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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM