Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to omp_get_wtime

Tags:

c++

gcc

openmp

I cannot find which library to link in GCC (4.8) under Windows (Vista). I tried the -fopenmp -llibgomp -lgomp compiler directives, but none works.

I already have GCC with POSIX (so std::thread is working if enabling C++11). The problem seems that searching for the right library does not provide useful results (even searching in GCC/MinGW documentation).

So basically I can't get this answer working (the answer claimed to work on most compilers, but it doesn’t provide additional information on how to get it working, so I can't verify if it is really working or not).

It would be nice to provide now additional information to get it working on most systems...

like image 701
CoffeDeveloper Avatar asked Oct 12 '13 08:10

CoffeDeveloper


1 Answers

MinGW-w64 based on GCC 4.8.1 from here has no problems so far.

Example: C


main.c

#include <omp.h>
#include <stdio.h>

int
main() {
  double x = omp_get_wtime();

  printf("%f\n", x);
}

Build:

gcc main.c -lgomp -o test.exe

Result:

1381572544.299000

Example: C++


main.cpp

#include <iostream>
#include <omp.h>

using std::cout;
using std::endl;

int
main() {
  double x = omp_get_wtime();

  cout << x << endl;
}

Build:

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

Result:

1.38158e+009

Conclusion


Probably something is wrong with your MinGW distribution. Otherwise I don't see any reason for it not to work. Try the above one and see how it goes.

like image 102
Alexander Shukaev Avatar answered Oct 23 '22 09:10

Alexander Shukaev