c++ - 未定义对 `omp_get_wtime' 的引用

标签 c++ cmake clion

我学习c++、OpenMP。我尝试使用 omp_get_wtime 编译我的程序,但它不起作用,但是当我删除它时,它起作用了。我必须添加一些东西,但是什么以及在哪里。在 openmptryflags 或 Cmakelists 中?

snap/clion/61/bin/cmake/linux/bin/cmake --build /home/bapah/CLionProjects/omp1/cmake-build-debug --target omp1 -- -j 6
[ 50%] Linking CXX executable omp1
CMakeFiles/omp1.dir/main.cpp.o: In function `main':
/home/bapah/CLionProjects/omp1/main.cpp:36: undefined reference to `omp_get_wtime'
collect2: error: ld returned 1 exit status
CMakeFiles/omp1.dir/build.make:83: recipe for target 'omp1' failed
make[3]: *** [omp1] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/omp1.dir/all' failed
make[2]: *** [CMakeFiles/omp1.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/omp1.dir/rule' failed
make[1]: *** [CMakeFiles/omp1.dir/rule] Error 2
Makefile:118: recipe for target 'omp1' failed
make: *** [omp1] Error 2

最佳答案

解决方案: 添加到 CMakeList.txt

SET_TARGET_PROPERTIES(omp1 PROPERTIES COMPILE_FLAGS "-fopenmp"
    LINK_FLAGS "-fopenmp")

P.s. omp1 - 为您的项目命名。

P.p.s。您也可以编写 target_link_libraries(omp1 -fopenmp)

关于c++ - 未定义对 `omp_get_wtime' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54934933/

相关文章:

c++ - 在 C++ 中添加包含多个文件的库

c++ - Sfinae 模板化隐式转换运算符重载

cmake - CppUnit 测试总是通过 Ctest

c++ - 如何在 Windows 上的 CMakelist.txt 中包含 Eigen 库

c++ - 关于将字符串传递给 win32 api 函数

c++ - 使用 aho-corasick 算法崩溃?

linux - 在 Linux 中为多个 Python 版本安装 OpenCV

c++ - 安装 dlib 时出错

c++ - Gurobi 和 C++ - 如何使用 Clion 协同工作

clion 更改默认项目模板