Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Calling dsygv from C++

troels_roennow
Beginner
492 Views
Hey,

I am currently having trouble when I try to link to the dsygv from LAPACK. This has caused me trouble and I have made an exmaple of my problem here: http://www.numericalsnippets.com/recipes/s/cpp/c6e437a87f3beb087620eeeba8bf0bf1/. My project consists of two files eiglib.cpp and eiglink.cpp. The first file is a library that uses dsygv to calculate an eigenvalue and eiglink is the main application.

Compiling the application as given it works, but if you outcomment line 53, the linker says:

eiglib.o: In function `eig()':
eiglib.cpp:(.text+0xe0): undefined reference to `dsygv'
make: *** [test_lin64_link] Error 1

Thus, my library depends upon wether I use the dsygv in the main program or not. A work around for this would of course be to make a dummy function that called dsygv, but it would be a rather ugly solution imo.

Furthermore, I only have the problem on linux, not on my mac. This problem occurs to be a bit strange and any help is appreciated. I am not an expert in compiler flags and believe that the error is to be found there. You can find the make file in the bottom of the source.

Thanks in advance.
Troels
0 Kudos
1 Solution
TimP
Honored Contributor III
492 Views
In libmkl_intel_lp64.a, you're right, dsygv and dsygv_ are defined as duplicate entry points, as well having identical definitions in the include file.
You don't show a linking command; for relative simplicity, I tried
icpc -openmp eiglib.cpp -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread
and
icpc eiglib.cpp -lmkl_core -lmkl_intel_lp64 -lmkl_sequential
and I couldn't see your point about not resolving the symbol, unless I omitted one of those required libraries.
If you want static MKL libraries, there is a link advisor tool on the MKL forum. You will have a link order dependency with the static libraries, if you don't follow the advice there or in the release notes.

View solution in original post

0 Kudos
4 Replies
TimP
Honored Contributor III
492 Views
It appears that you haven't observed the spelling of dsygv_ in the linux header and lapack libraries. I don't know if that is different for Mac. This is not generally considered strange; the appended underscore convention for Fortran linkage goes back at least to BSD4.3 (well before the first Mac). Presumably, if you set appropriate compiler options, you would be warned about undefined function references.
0 Kudos
troels_roennow
Beginner
492 Views
Hey Tim,

Thanks for your reply. It is completely intended that I left out the underscore as I read in the manual that it makes no difference. Today I have just tried to introduce the underscore everywhere I use dsygv (tat is, replace: -dsygv -> dsygv_). It makes no differece! I still get the same behaviour where I have to call the dsygv from the main file before it works with the linked file.

Troels

PS: Please tell if you had success running my code with line 53 outcommented on a 64-bit linux box.
0 Kudos
TimP
Honored Contributor III
493 Views
In libmkl_intel_lp64.a, you're right, dsygv and dsygv_ are defined as duplicate entry points, as well having identical definitions in the include file.
You don't show a linking command; for relative simplicity, I tried
icpc -openmp eiglib.cpp -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread
and
icpc eiglib.cpp -lmkl_core -lmkl_intel_lp64 -lmkl_sequential
and I couldn't see your point about not resolving the symbol, unless I omitted one of those required libraries.
If you want static MKL libraries, there is a link advisor tool on the MKL forum. You will have a link order dependency with the static libraries, if you don't follow the advice there or in the release notes.
0 Kudos
troels_roennow
Beginner
492 Views
Fantastic. Thank you for helping me out with the compiler flags - everything seems to work now :)
0 Kudos
Reply