【问题标题】:undefined reference to `omp_get_wtime'未定义对“omp_get_wtime”的引用
【发布时间】:2019-07-22 21:56:06
【问题描述】:

我学习 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%] 链接 CXX 可执行文件 omp1 CMakeFiles/omp1.dir/main.cpp.o:在函数“main”中: /home/bapah/CLionProjects/omp1/main.cpp:36:未定义对“omp_get_wtime”的引用 collect2:错误:ld 返回 1 个退出状态 CMakeFiles/omp1.dir/build.make:83:目标“omp1”的配方失败 make[3]: *** [omp1] 错误 1 CMakeFiles/Makefile2:72:目标“CMakeFiles/omp1.dir/all”的配方失败 make[2]: *** [CMakeFiles/omp1.dir/all] 错误 2 CMakeFiles/Makefile2:84:目标“CMakeFiles/omp1.dir/rule”的配方失败 make[1]: *** [CMakeFiles/omp1.dir/rule] 错误 2 Makefile:118: 目标“omp1”的配方失败 制作:*** [omp1] 错误 2

【问题讨论】:

  • 听起来您可能缺少-fopenmp。您可以在问题中添加编译器或链接器命令行吗?
  • 我必须在哪里添加-fopenmp?
  • 恐怕我不知道。我使用不同的构建工具。
  • 你用什么? ubuntu 有什么更好的。我使用 Clion 和 Cmake
  • 如何在工具中添加-fopenmp?

标签: c++ cmake clion


【解决方案1】:

解决方案: 添加到 CMakeList.txt

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

附: omp1 - 为您的项目命名。

P.p.s.你也可以写target_link_libraries(omp1 -fopenmp)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 2022-01-22
    • 2016-04-04
    • 2015-11-03
    • 2011-08-11
    • 2015-07-20
    • 2019-06-22
    • 2012-04-02
    相关资源
    最近更新 更多