MinGW 上具有 OpenMP 支持的 Qt 插件:未定义的参考?
我正在开发一个使用 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_endCMakeFiles\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 toGOMP_parallel_stat'
GOMP_parallel_end
CMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:C:/svnosaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/thresholdPlgin/ui/dialogthresholdconfig.cpp:221:
undefined reference toCMakeFiles\RinzoDLPluginIPThreshold.dir\ui\dialogthresholdconfig.cpp.obj:
In functionZN21DialogThresholdConfig9slotApplyEv.omp_fn.0':
omp_get_nu_threads'
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223:
undefined reference to
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:223:
undefined reference toomp_get_thead_num'
omp_get_thead_num' collect2: ld
C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/imageprocplugins/threholdPlugin/ui/dialogthresholdconfig.cpp:233:
undefined reference to
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenMP 需要一个运行时库(在 gcc 中称为 libgomp),该库必须链接到创建的可执行文件中。因此,将 OpenMP 标志添加到编译标志是不够的,还必须将它们添加到链接标志:
当然,您需要将
替换为目标的实际名称。顺便说一句,像 OPENMP_ENABLE 这样的额外定义是多余的。如果启用 OpenMP,则会隐式定义宏
_OPENMP
以包含受支持的 OpenMP 版本(更准确地说,是受支持标准的发布日期)。您可以使用此宏来测试源代码中的 OpenMP 支持: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: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: