2

I have trouble making Clang work with MinGW on Windows. I have MinGW-W64-builds-4.3.3 installed (GCC 7.2.0) as well as the newest Clang/LLVM (by installer on the website).

I am compiling with:

-target x86_64-pc-windows-gnu 

option and Clang finds all the headers. Unfortunately there is an error from the linker when I am using OpenMP. It looks like this:

: undefined reference to `__imp___kmpc_fork_call'
\libgomp.a(team.o):(.text+0x19): undefined reference to `pthread_mutex_destroy'
...

When I try to use -fopenmp=libomp flag I am getting errors like this:

...: undefined reference to `__imp___kmpc_fork_call'
...: undefined reference to `__imp___kmpc_for_static_init_4'
...: undefined reference to `__imp___kmpc_for_static_fini'
...: undefined reference to `__imp___kmpc_barrier'
...

It all works without problems when compiling with GCC. Is there a way to make it (openmp) work without Visual Studio installed? If no, is there some minimilastic Visual Studio installer which just pulls needed libraries/headers and not the whole IDE etc.?

I surely don't know what I am doing here. Explain like I am five answers are very appreciated.

Piotr Lopusiewicz
  • 2,514
  • 2
  • 27
  • 38
  • 1
    You may have better luck with `-fopenmp=libiomp5` (issue similar to yours: https://stackoverflow.com/questions/45983643/openmp-not-linking-correctly-when-compiling-with-clang) – valiano Jan 06 '18 at 19:25

1 Answers1

0

What solved the issue for me was adding libomp.lib to the list of files to compile. This seems to be necessary no matter if I have -static in compiler options and no matter if it's:

-fopenmp=libomp

or

-fopenmp=libiomp5

(as the commenter suggested)

Summing things up, I needed:

clang --target x86_64-pc-windows-gnu -fopenmp=libomp ... C:\FULL\PATH\TO\libomp.lib

To make it work with MinGW-W64-builds-4.3.3 and Clang 5.0.1

Piotr Lopusiewicz
  • 2,514
  • 2
  • 27
  • 38