Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28991 Discussions

problem linking libraries in a program employing openmp

normcler
Beginner
427 Views
Hello everyone,

I am trying to build a program that employs openmp, and I have a problem
linking the correct libraries.

I am using a Ubuntu 10.04 linux system; when I build the program without
using openmp, there are no problems or errors, the program builds and runs
correctly.

There are many error messages at the link stage similar to

/home/norm/opcon/src/zoommtf.f90:944: undefined reference to
`__kmpc_global_thread_num'

Based on searches on the Internet and the forum, it seems that the openmp
runtime libraries are not being correctly linked, if at all.

Here is an inquiry into the installtion directory of the compiler:

norm@lima:/opt/intel$ find . -name 'lib*omp*'
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_clpt_3.1.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiompstubs5.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/
libcomposerxe_boost_date_time_1.34.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_cpil_2.9.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_rdmgr_2.1.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiompprof5.a
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/
libcomposerxe_gen_helpers_core_2.3.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_libxml_2.7.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_boost_thread_1.
34.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiomp5.a
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/locale/ja_JP/libiomp5.cat
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/
libcomposerxe_gen_helpers_das_2.3.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiompstubs5.a
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_cfgmgr_2.4.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_boost_system_1.
34.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiomp5.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_msngr_reader_2.4
.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_msngr_cmd_2.4.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libiompprof5.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_boost_regex_1.34
.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/
libcomposerxe_boost_filesystem_1.34.so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libcomposerxe_msngr_util_2.4.
so
./composer_xe_2011_sp1.7.256/compiler/lib/intel64/libomp_db.so

Here are the entries containing the word "path" in my environment:

norm@lima:~/opcon$ env |egrep -i 'path'
MANPATH=/opt/intel/composer_xe_2011_sp1.7.256/man/en_US:/opt/intel/
composer_xe_2011_sp1.7.256/man/en_US:/opt/intel/composerxe/man:/usr/local/man:/
usr/local/share/man:/usr/share/man:
LIBRARY_PATH=/opt/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/opt/
intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/opt/intel/
composer_xe_2011_sp1.7.256/mkl/lib/intel64
FPATH=/opt/intel/composer_xe_2011_sp1.7.256/mkl/include
LD_LIBRARY_PATH=/opt/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/opt/
intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/opt/intel/
composer_xe_2011_sp1.7.256/mkl/lib/intel64:/opt/gcc-trunk/lib64:/opt/intel/
composer_xe_2011_sp1.7.256/debugger/lib/intel64:/opt/intel/composer_xe_2011_sp1.
7.256/mpirt/lib/intel64
CPATH=/opt/intel/composer_xe_2011_sp1.7.256/mkl/include
DEFAULTS_PATH=/usr/share/gconf/gnome.default.path
NLSPATH=/opt/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64/locale/%l_%t/
%N:/opt/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64/locale/%l_%t/%N:/opt/
intel/composer_xe_2011_sp1.7.256/debugger/intel64/locale/%l_%t/%N
PATH=/opt/intel/composer_xe_2011_sp1.7.256/bin/intel64:/opt/intel/composerxe/bin
:/opt/pgi/linux86-64/11.6/bin:/home/norm/bin:/usr/local/sbin:/usr/local/bin:/usr
/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/intel/composer_xe_2011_sp1.7.256/mpirt
/bin/intel64
MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path

Based on this, it would seem that the LD_LIBRARY_PATH correctly includes the
paths to all the compiler libraries.

The following line shows the compiler directive for a file with all the
compiler flags:

ifort -auto -check bounds -check pointers -check uninit -warn declarations
-warn unused -I /home/norm/opcon/include -stand f03 -warn general
-debug-parameters -ftrapuv -debug full -openmp -static-intel -v -V
-L/opt/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64 -c -o syskinds.o
syskinds.f90

Here is the beginning of the invocation of the linker, showing the link flags:

ifort -g -L/opt/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64 -o
focus11 syskinds.o formatbank.o charutil.o timestampmod.o debugmod.o parlist.o
enummod.o numrutil.o glparams.o optparam.o syspars.o param.o opconkinds.o
constants.o emitterray.o rayinfo.o pbi

Does anyone have any idea, given this data, why the libraries are not being
linked?

Norm Clerman

0 Kudos
3 Replies
TimP
Honored Contributor III
427 Views
You should include the same library-related options in the ifort link command as you used earlier. -openmp will add implicitly the necessary -liomp5 -lpthread to the linker script.
-static-intel would not affect the choice of libiomp5.so (dynamic OpenMP library), so you would still require the library directory to appear in LD_LIBRARY_PATH for successful run.
0 Kudos
normcler
Beginner
427 Views
Thanks, that worked fine. Permit me to add that the -openmp option is not listed in the manual as a link option.

Norm
0 Kudos
Steven_L_Intel1
Employee
427 Views
It isn't a link option, but it is an option to ifort that modifies the link step.
0 Kudos
Reply