Linking to ARPACK from VS2010

1.2k Views Asked by At

I am trying to get the ARPACK library to run on VS2010.

I would like to use the C++ wrappers provided by ARPACK++ (some background - i need to get eigenvalues and eigenvectors of huge matrices). There is a very good tutorial on the subject here.

Following the tutorial i've managed to compile the fortran code using g77 on mingw, i successfully generated the dll and lib as described. The problem arises when trying to link my visual studio project to the library.

The way i'm trying to link is as follows:

  1. I've made a simple VS2010 C++ console app
  2. i've added the the folder containing ARPACK++ libraries to my "additional include folders"
  3. i've added the lib file to "Additional dependencies"
  4. i've added the directory containg the lib file to my "Additional library directories"

Despite these settings when i try to compile this short test code:

#include "stdafx.h"
#include "arrsnsym.h"

int _tmain(int argc, _TCHAR* argv[])
{
    ARrcNonSymStdEig<float> prob(100, 4L);
    printf("Bok!");
    return 0;
}

I get an error saying:

>arpackcpp.obj : error LNK2001: unresolved external symbol scopy_
1>arpackcpp.obj : error LNK2001: unresolved external symbol snaupd_
1>arpackcpp.obj : error LNK2001: unresolved external symbol sneupd_

I do not understand why the linker can't find the mentioned methods. Inspecting the .def file generated by the dllwrap utility does indeed mention all these functions so i am fairly sure they should be available. Still, i feel i'm missing something obvious.

UPDATE (got it working!):

It turns out that i was trying to link a 64 bit program to a 32 bit library, when switching to x86 in the Configuration settings AND including the generated def file in Configuration Properties -> Linker -> Input -> Additional definition file, it worked for 32bit (however i needed 64). The final solution that worked for me was to cross compile it for Win64 using MinGW and gfortran on linux. That worked surprisingly well and produced a dll to which i could link from a 64bit C++ app in VS. I think i should now go write a tutorial on how to do this :)

1

There are 1 best solutions below

2
On

My guess is that this is a name-mangling scheme issue. In fortran, it is not well defined what name the symbols will have in the object file's symbol table. For example, a routine named foo could end up in the symbol table as foo,FOO,foo_,foo__ and so on. These days, I don't know of too many compilers that use double underscores (with g77 being the exception). I'm assuming the ARPACK++ wrappers are assuming a single underscore. The solution here is to tell the compiler to use single underscores in the symbol names (with g77, that means using -fno-second-underscore). Note that gfortran is a newer (still supported) open-source fortran compiler which does single underscoring by default. You might want to try to build your code using that compiler as well. (It might produce more optimized output than g77.)