Little Fighter Empire - Forums

Full Version: openMP not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys!

So what i am trying to do is using some directives from openMP in C programs.
But he problem is that whenever i try to run the program it says:

undefined reference to `omp_get_thread_num'

I have been using various examples from internet and all of them have the same problem. It runs OK when there is not any 'omp_get_thread_num' or omp_get_wtime'. But of course i need these two in my programs.

I have MinGW (2 versions: one about the end of 2013 and the other one downloaded less then 1 month ago). I have tried in eclipse, codeblock and commandline. when i try it to cmd it says "can't find -lpthread"

i have tried in 2 different machines both Windows10 64bit

i have been trying to find anything in internet for about one week but no result :s

idk what i am missing here.
The compiler is not finding the library containing the definitions of these methods to link against. You need to use "-fopenmp" as a linker option for the functions you mentioned to work. On code::blocks, go settings->compiler settings->linker settings tab->append "-fopenmp" to what's in the "other linker options" box.

If that doesn't work, it would help if you'd show the command you attempted to compile your program with.
(03-08-2016, 04:51 PM)A-Man Wrote: [ -> ]The compiler is not finding the library containing the definitions of these methods to link against. You need to use "-fopenmp" as a linker option for the functions you mentioned to work. On code::blocks, go settings->compiler settings->linker settings tab->append "-fopenmp" to what's in the "other linker options" box.
It should be added it to project's linker settings, not the global compiler's linker settings. This way if you ever distribute the project it will work for other people without them having to modify their global compiler settings.
Ah, you're right. So:
right click on project in inspector->project build options->linker settings tab
gcc -fopenmp path\file.c -o path\file

or

gcc -fopenmp path\file.c -o path\file.exe

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status


After adding "-fopenmp" in "other linker options" in eclipse (in project settings) it gives me this result:
[New Thread 5292.0x4ac]
[New Thread 5292.0x324]
error return ../../gdb-7.6.1/gdb/windows-nat.c:1275 was 5


Or here is the console while it is trying to exe **** Internal Builder is used for build ****
gcc -Xlinker -fopenmp -o engine1.exe src\engine1.o
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: -f may not be used without -shared
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 125 ms.

Same thing when i use Gnu make builder instead of internal builder


Also i tried to put "-fopenmp" not in other options, but in linker flags, to avoid that -Xlenker=> same result

And here is a very simple code i just tried to run:
    C-Code:
#include <stdio.h>
#include <omp.h>
 void main()
 {
 #pragma omp parallel
 {
 int ID = 0;
 ID= omp_get_thread_num();
 
 printf("Hello World (%d) \n",ID);
 }
 }


I will try this on CodeBlock tomorrow.
The command should work fine if your compiler supports the specification with that function. What version of gcc do you use? You can type "gcc --version" to get that information. I can confirm that your snippet compiles in gcc 5.2.
(03-08-2016, 10:09 PM)empirefantasy Wrote: [ -> ]c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
GCC 4.8.1 is hella old.
Download this: https://sourceforge.net/projects/mingw-w...e/download
Or if you prefer to unzip instead of running an installer https://sourceforge.net/projects/mingw-w...z/download

Get rid of older versions of GCC so you are sure they won't affect anything, and use the new version. (in Code::Blocks this will require updating the path under Settings>Compiler...>Toolchain Executables and then updating the different fields to match)
ok thanks guys :D

i installed version 5.2 and after some tests i were able to run a program like it via cmd.

i have to note that it gave me error for some dll files, but which in fact they existed in mingw32/bin folder. anyways i copied them to my file folder and so it became able to be executed.

thanks for help

works great in codeblock too :D