Community
cancel
Showing results for 
Search instead for 
Did you mean: 
utab
Beginner
45 Views

calling intel fortran compiled library and g++

Dear all,

In my C++ code, I have to call functions from a shared fortran library, I am almost there however I would like my code also to work with the g++. Using g++ I am getting

/opt/ansys-12.1/v121/ansys/customize/misc/linx64/libbin.so: undefined reference to `__kmpc_end'
/opt/ansys-12.1/v121/ansys/customize/misc/linx64/libbin.so: undefined reference to `__kmpc_global_thread_num'
/opt/ansys-12.1/v121/ansys/customize/misc/linx64/libbin.so: undefined reference to `__kmpc_begin'

So the commerical program is ansys and most probably it is compiled for my system with intel compiler. Using icpc and -parallel link option solves this problem, however where are these symbols coming from os that I can explicitly know how to link them with also g++.

Any help is appreciated.

Umut
0 Kudos
4 Replies
TimP
Black Belt
45 Views

Those functions would be defined in libiomp5, which is added automatically to the link by icpc -parallel or -openmp, but would have to be given explicitly for g++, e.g. by -L and -l, or specifying full path name of libiomp5.
utab
Beginner
45 Views

Thanks for the reply, ok I found out the shared object you mentioned, and it is located under

/home/utabak/intel/composerxe-2011/lib/intel64/libiomp5.so

so using -L /home/utabak/intel/composerxe-2011/lib/intel64/libiomp5.so -liomp5

after that I got another undefined reference with g++

/home/utabak/intel/composerxe-2011/lib/intel64/libiomp5.so: undefined reference to `pthread_atfork'

adding -pthread option to g++ solves this problem. Compile and link goes fine however running the binary gives a problem this time and, randomly, the error message changes from run to run. Investigating a bit more, I realized that If I compile the file with

icpc -parallel -o test1 test_binlib1.cc -I/home/utabak/external_libraries/boost_1_46_1 -L /opt/ansys-12.1/v121/ansys/syslib/linx64/ -L /opt/ansys-12.1/v121/ansys/customize/misc/linx64 -lbin

the executable works fine, however if I split that to a make file as such

CXX = icpc -g -parallel -Wall

IncludeDir = /home/utabak/external_libraries/boost_1_46_1

LinkingDir0 = /home/utabak/external_libraries/boost_1_46_1/stage/lib
LinkingDir1 = /opt/ansys-12.1/v121/ansys/syslib/linx64/
LinkingDir2 = /opt/ansys-12.1/v121/ansys/customize/misc/linx64
#LinkingDir3 = /home/utabak/intel/lib/intel64
LibLink1 = bin
LibLink2 = boost_filesystem
LibLink3 = boost_system

all: test1

test1: test_binlib1.o
${CXX} -o $@ $? -L${LinkingDir0} \
-L${LinkingDir1} -L${LinkingDir2} \
-l${LibLink1} -l${LibLink2} -l${LibLink3}


test_binlib1.o: test_binlib1.cc
${CXX} -I${IncludeDir} -c $?

compile and link goes fine but the executable does not work, it gives me an error with either segmentation fault due to this fortran function calls in C++ code or either file could not be opened for reading by again the fortran library function calls.

What is my error in buiding up the make file since the above given one liner compilation command works fine, I am pretty puzzled.

Best,
Umut




utab
Beginner
45 Views

As a folllow up to my reply:

If I do not put the debugging option -g there everything works fine, with the debugging flags -g or -debug all, none of my executables are working properly, I am quite puzzled now...
TimP
Black Belt
45 Views

You have a lot more information in front of you than we do. If you sort out your Makefile so that the steps make takes match your successful command line, does it help? In particular, you are linking against your libraries in a different order.