undefined reference to omp_get_wtime

21,776

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.

Share:
21,776
CoffeDeveloper
Author by

CoffeDeveloper

Updated on November 21, 2020

Comments

  • CoffeDeveloper
    CoffeDeveloper over 3 years

    I cannot find wich library to link in GCC (4.8) under windows (vista). I tried -fopenmp -llibgomp -lgomp compiler directives but no one works.

    I already have GCC with POSIX (so std::thread working if enabling C++11), the problem seems that searching for the right library does not provide usefull results (even searching on GCC/mingw documentation).

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

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

    Thanks!

  • CoffeDeveloper
    CoffeDeveloper over 10 years
    I re-downloaded GCC 4.8 distribution, now it compiled but measured times have a resolution of 15 milliseconds :/ no more than ctime
  • Alexander Shukaev
    Alexander Shukaev over 10 years
    The feature you want to test is very implementation dependent. Maybe both of them already use high-resolution OS clock by default under the hood, and that's why you don't see any difference. Another possibility is that your benchmark has some wrong assumptions and/or is measuring too small unit of workload to capture the difference between these 2 timers.
  • vincent mathew
    vincent mathew over 8 years
    It worked for me. Thanks. I didn't know one has to add this.