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++.
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.
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
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.
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.