错误"undefined reference to omp_get_wtime"

Error "undefined reference to omp_get_wtime"

本文关键字:get wtime omp to undefined reference 错误      更新时间:2023-10-16

我在Windows(Vista(下的GCC(4.8(中找不到要链接的库。我尝试了-fopenmp -llibgomp -lgomp编译器指令,但没有一个有效。

我已经有了带有 POSIX 的 GCC(所以如果启用 C++11,std::thread 就可以工作了(。问题似乎是搜索正确的库并不能提供有用的结果(即使在GCC/MinGW文档中搜索也是如此(。

所以基本上我无法让这个答案工作(答案声称适用于大多数编译器,但它没有提供有关如何使其工作的其他信息,所以我无法验证它是否真的有效(。

现在提供额外的信息以使其在大多数系统上工作会很好......

基于

GCC 4.8.1的MinGW-w64到目前为止没有任何问题。

示例:C

<小时 />

主.c

#include <omp.h>
#include <stdio.h>
int
main() {
  double x = omp_get_wtime();
  printf("%fn", x);
}

建:

gcc main.c -lgomp -o test.exe

结果:

1381572544.299000

示例:C++

<小时 />

主.cpp

#include <iostream>
#include <omp.h>
using std::cout;
using std::endl;
int
main() {
  double x = omp_get_wtime();
  cout << x << endl;
}

建:

g++ main.cpp -lgomp -o test.exe

结果:

1.38158e+009

结论

<小时 />

您的 MinGW 分布可能有问题。否则,我认为它没有任何理由不起作用。试试上面的一个,看看它是如何进行的。