简体   繁体   English

CMake:如何强制将 cmake 链接到 static 链接 openmp?

[英]CMake: How can I force cmake to static link openmp?

I know the way to use cmake to link openmp in a cross-platform way我知道使用 cmake 以跨平台方式链接 openmp 的方法

find_package(OpenMP REQUIRED)
link_libraries(OpenMP::OpenMP_CXX)

But I don't know how to force cmake to static link openmp , in fact, all of cmake official variable about openmp library is all dynamic .但是我不知道如何强制cmake 到static 链接openmp ,实际上关于openmp 库的所有cmake 官方变量都是动态的。
Anyway, The non-cross-platform way to do so is:无论如何,这样做的非跨平台方式是:

clang++ -std=c++2a test.cpp -Iinclude -march=native -O3 -c          
clang++ test.o -o test.x /usr/local/lib/libomp.a -pthread  

or if you use gcc或者如果您使用 gcc

g++-10 -std=c++2a test.cpp -Iinclude -march=native -O3 -c 
g++-10 test.o -o test.x /usr/local/opt/gcc/lib/gcc/10/libgomp.a -pthread 

By the way, is it a cmake defect or is there any other way to accomplish it顺便说一句,它是 cmake 缺陷还是有其他方法可以完成它

Not an answer but too much to fit into a comment.不是答案,而是太多无法放入评论。

I don't know anything about OpenMP other than cmake does support it: https://cmake.org/cmake/help/latest/module/FindOpenMP.html?highlight=openmp .除了 cmake 支持它之外,我对 OpenMP 一无所知: https://cmake.org/cmake/help/latest/module/FindOpenMP.html?highlight=openmp

I don't see any of the documentation referring to static/shared.我没有看到任何涉及静态/共享的文档。 Maybe you are correct and it only support shared libs.也许你是对的,它只支持共享库。

Double check by asking the official make discourse: https://discourse.cmake.org/通过询问官方make discourse仔细检查: https://discourse.cmake.org/

You could also try reading the official FindOpenMP.cmake module since this is all open source.您也可以尝试阅读官方的 FindOpenMP.cmake 模块,因为这都是开源的。

EDIT:编辑:

If you are correct cmake is lacking this functionality consider contributing and adding it:)如果您是正确的 cmake 缺少此功能,请考虑贡献并添加它:)

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

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