Author Topic: How to enable OpenMP with C::B?  (Read 71340 times)

Offline dvb

  • Single posting newcomer
  • *
  • Posts: 4
How to enable OpenMP with C::B?
« on: August 15, 2010, 03:22:41 am »
Hi,

I'm relatively new with C++, I want to build a small program for batch image manipulation.

For the program to be faster I must enable OpenMP, I've tried to add "-fopenmp" to "Settings -> Compiler and debugger... -> Other options" and execute the "trivial test program" from http://openmp.org/wp/openmp-compilers/ :
Code
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
but I'm still receiving:
Quote
-------------- Build: Debug in consoleTest ---------------

Linking console executable: bin\Debug\consoleTest.exe
obj\Debug\main.o: In function `main':
D:/path/to/consoleTest/main.cpp:16: undefined reference to `GOMP_parallel_start'
D:/path/to/consoleTest/main.cpp:16: undefined reference to `GOMP_parallel_end'
obj\Debug\main.o: In function `main.omp_fn.0':
D:/path/to/consoleTest/main.cpp:17: undefined reference to `omp_get_num_threads'
D:/path/to/consoleTest/main.cpp:17: undefined reference to `omp_get_thread_num'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
4 errors, 0 warnings
 
« Last Edit: August 15, 2010, 12:23:17 pm by dvb »

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: How to enable OpenMP with C::B?
« Reply #1 on: August 15, 2010, 11:21:20 am »
The option may be "-fopenmp".
Regards,
xunxun

Offline dvb

  • Single posting newcomer
  • *
  • Posts: 4
Re: How to enable OpenMP with C::B?
« Reply #2 on: August 15, 2010, 12:24:56 pm »
Yeah I meant -fopenmp
(fixed the first post)

thank you anyway for your time :)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to enable OpenMP with C::B?
« Reply #3 on: August 15, 2010, 03:27:12 pm »
You have to link against the OpenMP library.
On linux it's enough to add gomp to the projects "Linker settings -> Link libraries" (just gomp no pre- or suffix).
On windows you most likely need to add the directoy where the library is (probably libgomp.dll or something like that) to "Search directories -> linker".
If it is in the compilers lib subdir, you do not need that, but I have absolutely no clue, where it is on win.
Maybe you have to compile the library yourself on windows, to make it usablke with your compiler-version.

But how to do that is something, that you should ask in an OpenMP forum not here.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: How to enable OpenMP with C::B?
« Reply #4 on: August 16, 2010, 12:35:10 am »
the dll itself resides in mingw/bin on windows the library is in /mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a -fopenmp seems to be enough on most things i tried that could actually use it :)

Offline dvb

  • Single posting newcomer
  • *
  • Posts: 4
Re: How to enable OpenMP with C::B?
« Reply #5 on: August 16, 2010, 12:53:33 am »
the dll itself resides in mingw/bin on windows the library is in /mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a -fopenmp seems to be enough on most things i tried that could actually use it :)
I've found '/mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a' and added the absolute path of '....\MinGW\lib\gcc\mingw32\4.4.1\' to the search directories. I've also put '-fopenmp' but I still receive the errors...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to enable OpenMP with C::B?
« Reply #6 on: August 16, 2010, 09:30:20 am »
the dll itself resides in mingw/bin on windows the library is in /mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a -fopenmp seems to be enough on most things i tried that could actually use it :)
I've found '/mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a' and added the absolute path of '....\MinGW\lib\gcc\mingw32\4.4.1\' to the search directories. I've also put '-fopenmp' but I still receive the errors...
Remove the path from search directories and add gomp to the link libraries !

Offline dvb

  • Single posting newcomer
  • *
  • Posts: 4
Re: How to enable OpenMP with C::B?
« Reply #7 on: August 16, 2010, 01:28:54 pm »
thanks, seems like it's the right direction... but now I'm receiving a new error in the build log:
"Process terminated with status -1073741515"

I'm also receiving a box message (I'm on a non-english system so this may not be the exact translation):
Title: "OpenMP_Test.exe - system failure"
Message: "{Unable To Locate Component} This application has failed to start because libgomp-1.dll was not found. Re-installing the application may fix this problem."

(BTW, I want this application to be cross-platform)
« Last Edit: August 16, 2010, 01:30:28 pm by dvb »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to enable OpenMP with C::B?
« Reply #8 on: August 16, 2010, 01:45:20 pm »
The dll has to be in system path or in the exe's directory.

The easiest way is to add your MinGW's bin directory to the system-path.

ligand

  • Guest
Re: How to enable OpenMP with C::B?
« Reply #9 on: August 02, 2013, 09:36:42 am »
the dll itself resides in mingw/bin on windows the library is in /mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a -fopenmp seems to be enough on most things i tried that could actually use it :)
I've found '/mingw/lib/gcc/mingw32/(version number)/libgomp.dll.a' and added the absolute path of '....\MinGW\lib\gcc\mingw32\4.4.1\' to the search directories. I've also put '-fopenmp' but I still receive the errors...
Remove the path from search directories and add gomp to the link libraries !


Obvious the above is the right way!!!

I met the same problem: in C::B, compiled a small OpenMP example but got undefined reference to `omp_get_num_threads'
I have manually compiled and linked the example using mingw-gcc, but it is OK.
  g++ testOpenMP.cpp -o a.exe -fopenmp
I then manually compiled and linked standalone respectively,
   g++ testOpenMP.cpp -c -o testOpenMP.o -fopenmp
   g++ testOpenMP.o -o a.exe
the same problem occurred. If linked with -fopenmp, it is OK.

Conclusion: C::B executed the linker to create execute, not with -fopenmp link options.  The solution is  add gomp to the link libraries

Offline meth

  • Single posting newcomer
  • *
  • Posts: 2
Re: How to enable OpenMP with C::B?
« Reply #10 on: November 23, 2020, 06:55:49 am »
If you are using Ubuntu OS, just do the following

Go to Settings -> Compiler, and  then click on the compiler settings tab, then click other compiler options and type -fopenmp. To set the linkers, click on the linker settings tab, and type -lgomp -pthread in the white space under other linker options.