User forums > Help
How to enable OpenMP with C::B?
dvb:
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());
}
--- End code ---
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
--- End quote ---
xunxun:
The option may be "-fopenmp".
dvb:
Yeah I meant -fopenmp
(fixed the first post)
thank you anyway for your time :)
Jenna:
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.
reckless:
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 :)
Navigation
[0] Message Index
[#] Next page
Go to full version