MinGW 上具有 OpenMP 支持的 Qt 插件:未定义的参考?

发布于 2024-10-14 05:37:07 字数 2399 浏览 2 评论 0原文

我正在开发一个使用 OpenMP 的“Qt 插件”(可以使用 CMake 参数启用/禁用 OpenMP 支持)。我使用 MinGW 和 CMake 作为开发环境。 这就是我在代码中启用/禁用 OpenMP 的方法:

#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif  for(int i=0; i<volumeData->getZSize(); i++){  .

我已在 CMake 文件中启用 OpenMP,如下所示:

OPTION (OPENMP_SUPPORT  "Build with OpenMP parallaization enabled")

IF (OPENMP_SUPPORT)
 FIND_PACKAGE( OpenMP )
 SET(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS}")

 IF ( OpenMP_CXX_FLAGS )
  MESSAGE("------- Adding compiler parameter for OpenMP")
  ADD_DEFINITIONS(-DOPENMP_ENABLE)
 ENDIF()
ENDIF()

为了构建 Qt 插件,我已配置 CMake,如下所示:

ADD_DEFINITIONS(-DQT_PLUGIN)

ADD_DEFINITIONS(-DQT_SHARED)

此配置可以在 Linux 上正常编译。 在 Windows 中,无需 OpenMP 支持即可正常编译。 但是当使用 OpenMP 支持构建时,会出现错误

c:/mingw4/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: 警告:自动导入已 无需 --enable-auto-import 即可激活 在命令行上指定。这 应该有效,除非涉及 常量数据结构引用 自动导入 DLL 中的符号。 CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:C:/svnosaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/thresholdPlgin/ui/dialogthresholdconfig.cpp:221: 未定义的引用 GOMP_parallel_stat' CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:C:/svnosaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/thresholdPlgin/ui/dialogthresholdconfig.cpp:221: 未定义的引用GOMP_parallel_end

CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj: 功能中 ZN21DialogThresholdConfig9slotApplyEv.omp_fn.0': C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223: 未定义的引用omp_get_nu_threads' C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223: 未定义的引用 omp_get_thead_num' C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:233: 未定义的引用 omp_get_thead_num'collect2:ld 返回 1 退出状态 make[2]: * [dist/plugins/libRinzoDLPluginIPThreshold.dll] 错误1

​​这是我的完整 CMake 文件: http://www.keepandshare.com/doc/view.php ?id=2552392&da=y

有什么建议吗?

I am developing a "Qt Plugin" which uses OpenMP (OpenMP support can be enabled/disabled using CMake parameter). I use MinGW and CMake as development environment.
This is how I enable/disable OpenMP in the code:

#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif  for(int i=0; i<volumeData->getZSize(); i++){  .

I have enabled OpenMP in CMake file as follows:

OPTION (OPENMP_SUPPORT  "Build with OpenMP parallaization enabled")

IF (OPENMP_SUPPORT)
 FIND_PACKAGE( OpenMP )
 SET(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS}")

 IF ( OpenMP_CXX_FLAGS )
  MESSAGE("------- Adding compiler parameter for OpenMP")
  ADD_DEFINITIONS(-DOPENMP_ENABLE)
 ENDIF()
ENDIF()

and to build Qt plugin, I have configured CMake as follows:

ADD_DEFINITIONS(-DQT_PLUGIN)

ADD_DEFINITIONS(-DQT_SHARED)

This configuration compiles fine with Linux.
In Windows it compiles fine WITHOUT OpenMP support.
But when build with OpenMP support, it gives the error

c:/mingw4/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe:
warning:auto-importing has been
activated without --enable-auto-import
specified on the command line. This
should work unless it involves
constant data structures referencing
symbol from auto-imported DLLs.
CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:C:/svnosaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/thresholdPlgin/ui/dialogthresholdconfig.cpp:221:
undefined reference to
GOMP_parallel_stat'
CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:C:/svnosaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/thresholdPlgin/ui/dialogthresholdconfig.cpp:221:
undefined reference to
GOMP_parallel_end

CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:
In function
ZN21DialogThresholdConfig9slotApplyEv.omp_fn.0':
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223:
undefined reference to
omp_get_nu_threads'
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223:
undefined reference to
omp_get_thead_num'
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:233:
undefined reference to
omp_get_thead_num' collect2: ld
returned 1 exit status make[2]: *
[dist/plugins/libRinzoDLPluginIPThreshold.dll]
Error 1

Here is my complete CMake file:
http://www.keepandshare.com/doc/view.php?id=2552392&da=y

Any tip?

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

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

发布评论

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

评论(1

来世叙缘 2024-10-21 05:37:07

OpenMP 需要一个运行时库(在 gcc 中称为 libgomp),该库必须链接到创建的可执行文件中。因此,将 OpenMP 标志添加到编译标志是不够的,还必须将它们添加到链接标志:

set_target_properties(<target_name> LINK_FLAGS "${OpenMP_CXX_FLAGS}")

当然,您需要将 替换为目标的实际名称。

顺便说一句,像 OPENMP_ENABLE 这样的额外定义是多余的。如果启用 OpenMP,则会隐式定义宏 _OPENMP 以包含受支持的 OpenMP 版本(更准确地说,是受支持标准的发布日期)。您可以使用此宏来测试源代码中的 OpenMP 支持:

#if defined(_OPENMP)
// use openmp
#endif

OpenMP requires a runtime library (called libgomp in case of gcc), which must be linked into the created executable. It is therefore not sufficient to add the OpenMP flags to the compilation flags, they must also be added to the link flags:

set_target_properties(<target_name> LINK_FLAGS "${OpenMP_CXX_FLAGS}")

Of course, you need to replace <target_name> with the actual name of your target.

And by the way, and extra definition like OPENMP_ENABLE is superfluous. If OpenMP is enabled, the macro _OPENMP is implicitly defined to contain the supported version of OpenMP (more precisely, the release date of the supported standard). You can use this macro to test for OpenMP support in the source code:

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