Parallel program giving error "Undefined reference to _Kmpc_ok_to_fork"
fortran, intel, linux, openmp
Solution
A quick scan of the Intel forums suggests you may need the `-openmp` option on the second command as well, to cause it to link against the OpenMP libraries.
You could have found this yourself by Googling `__kmpc_global_thread_num`
Problem
I am trying to compile the OPENMP fortran code on linux. I have around 230 subroutines. The code I used to compile the code is as follows: 1) At first I compiled each subroutine with the following command ``` ifort -c -override-limits -openmp *.for ``` Then all the subroutines have now a separate object file. 2) Then I tried to compile the object files to the executable by the following command ``` ifort *.o -o myprogram ``` I got the following error : ``` WINDWAVE.F90:(.text+0x1c9d): undefined reference to `__kmpc_global_thread_num' WINDWAVE.F90:(.text+0x1cb0): undefined reference to `__kmpc_ok_to_fork' WINDWAVE.F90:(.text+0x1eea): undefined reference to `__kmpc_fork_call' WINDWAVE.F90:(.text+0x1f09): undefined reference to `__kmpc_serialized_parallel' WINDWAVE.F90:(.text+0x214b): undefined reference to `__kmpc_end_serialized_parallel' WINDWAVE.F90:(.text+0x2427): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x29c7): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x29da): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x2a50): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x3773): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x3786): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x37fc): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x4a58): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x4a6b): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x4a8f): undefined reference to `__kmpc_single' WINDWAVE.F90:(.text+0x4d18): undefined reference to `__kmpc_end_single' WINDWAVE.F90:(.text+0x4d2b): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x4da9): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x4fc5): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x4fd8): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x504e): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x596f): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x5982): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x59fb): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x6369): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x637c): undefined reference to `__kmpc_barrier' WINDWAVE.F90:(.text+0x63f2): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0x6b8d): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0x6ba0): undefined reference to `__kmpc_barrier' WINDWAVE.o: In function `windwave_mp_fetch_': WINDWAVE.F90:(.text+0x9cfd): undefined reference to `__kmpc_global_thread_num' WINDWAVE.F90:(.text+0x9d10): undefined reference to `__kmpc_ok_to_fork' WINDWAVE.F90:(.text+0x9da0): undefined reference to `__kmpc_fork_call' WINDWAVE.F90:(.text+0x9dbc): undefined reference to `__kmpc_serialized_parallel' WINDWAVE.F90:(.text+0x9e59): undefined reference to `__kmpc_end_serialized_parallel' WINDWAVE.F90:(.text+0xa0ea): undefined reference to `__kmpc_for_static_init_4' WINDWAVE.F90:(.text+0xa109): undefined reference to `__kmpc_for_static_fini' WINDWAVE.F90:(.text+0xa118): undefined reference to `__kmpc_barrier' ``` I am using intel 13 composer to compile the program. I didn't know how to use link with libiomp5md . Please help me get rid of this error. I tried several times but I couldn't get this error. If I don't use the openmp flag the program runs but it doesn't treat as openmp program. Thanks Jdbaba