levmar 2.6 with Visual Studio 2010

memo for compiling levmar 2.6 on windows with visual studio 2010.

we need to modify the code a bit for compilation!!!

  1. .lib files
    CmakeLists.txt of levmar 2.6 assumes that you put all lapack related .lib files into one directory. In Cmake GUI, it’s called LAPACKBLAS_DIR that is pre-defined as ‘/usr/lib’. If you compile clapack by yourself, the lib files are generated in different directories not in a directory. To use original CmakeLists.txt, you should put the .lib files into one directory and set LAPACKBLAS_DIR on Cmake GUI. Then, link problem should be solved.
  2. setting related to BLAS
    See the FAQ. We have to modify misc.h according to BLAS. The original misc.h assumes that you have a F77 BLAS. If your BLAS is either f2c’ed BLAS or CBLAS, you should modify a few lines in misc.h. If you compiled CLAPACK by yourself, your BLAS is f2d’ed one. Then, what you should do is

    1. Uncomment the line 31 of ”#define LM_BLAS_PREFIX f2c_”.
    2. Comment out the line 37 of “#define LM_BLAS_SUFFIX _
    3. Uncomment the line 35 of “#define LM_BLAS_SUFFIX”.
  3. HAVE_LAPACK
    check the HAVE_LAPACK option in cmake, and then compile it.

You can see how levmar works with an example program provided by the author.

Advertisements

7 thoughts on “levmar 2.6 with Visual Studio 2010

  1. Hi. Thanks for your various guides, but I just can’t get rid of the following error messages:
    3>levmar.lib(misc.obj) : error LNK2019: unresolved external symbol f2c_sgemm referenced in function slevmar_trans_mat_mat_mult
    3>levmar.lib(misc.obj) : error LNK2019: unresolved external symbol f2c_dgemm referenced in function dlevmar_trans_mat_mat_mult

    My steps so far:
    1) I downloaded clapack-3.2.1-CMAKE and compiled (using MSVC++2010Express):
    blas.lib; lapack.lib; libf2c.lib; tmglib.lib;…

    2) I downloaded Levmar2.6 and I intended to use CMake and MSVC++2010Express again to compile levmar.lib. But that would give the known error messages. I did change misc.h as described above, but that didn’t have the desired effect. Also, adding #include “blaswrap.h” to misc_core.c (as suggested on other sites) doesn’t help.

    Did you compile it for 32 or 64bit Windows? I am trying 64bit here (Cmake: current generator Visual Studio 10 Win 64).

    In a different guide you mentioned
    “Addition to the lib files, header files are necessary for using levmar.
    *.h: DIR_CLAPACK_SRC/SRC”.
    My DIR_CLAPACK_SRC/SRC doesn’t contain a single *.h file?!

    Please let me know if you have another idea on how to solve the issue! Thanks!

    • For quick answer, I compiled both clapack and levmar for 32 bit on 64bit windows. I’ll try compilation for 64 bit.

      f2c_sgemm and f2c_dgemm issue is BLAS name mangling problem as mentioned in levmar’s FAQ 27 http://www.ics.forth.gr/~lourakis/levmar/faq.html#Q27. One potential cause is your clapack .lib files. If your f2c_*gemm problems happen on either debug or release mode, clapack .lib files is not available for both mode. For example, I prepared lib files for both debug and release mode like
      blas.lib
      blasd.lib
      lapack.lib
      lapackd.lib
      libf2c.lib
      libf2cd.lib
      tmglib.lib
      tmglibd.lib

      I think “*.h: DIR_CLAPACK_SRC/SRC” was typo. It should be DIR_CLAPACK_SRC/INCLUDE, in which we have 3 .h files, blaswrap.h, clapack.h, and f2c.h.

    • John,
      I tried with Cmake with Visual Studio 10 Win 64 and successfully compiled. Now, I’m sure that your problem is related to blas. Did you change F2C_LIB_NAME from f2c to libf2c?

    • Hi John, I have exactly the same problem as you had. Even after I copied all the three .h files from clapack include folder to the levmar folder. Could you post what you did in details to solve this error? Thanks!

      • MT, here is my entire “script”. You might find what you were looking for…
        A: //Run CMake to compile Clapack
        1. Open CMake
        2. Where is the source code: DIR_CLAPACK_SRC (point it to the clapack folder)
        3. Where to build the binaries: DIR_CLAPACK_DST (ex. C:/CLAPACK) (choose destination folder)
        4. Press the “Configure” button. Choose your compiler (Visual Studio 10 Win64).
        5. In the middle window, tick the box next to “USE_BLAS_WRAP”. Then, press “Generate” to generate the selected build files. If the CMake part is successfully finished, the output is saved in DIR_CLAPACK_DST (your chosen folder from step 3).
        6. Open CLAPACK.sln (in DIR_CLAPACK_DST) with Visual Studio 2010 and build the project for “release”. If the build is successfully finished, the following files will have been generated:
        a. lapack.lib: DIR_CLAPACK_DST/SRC/Release
        b. tmglib.lib: DIR_CLAPACK_DST/Testing/MATGEN/Release
        c. libf2c: DIR_CLAPACK_DST/F2CLIBS/libf2c/Release
        d. blas.lib: DIR_CLAPACK_DST/BLAS/SRC/Release
        7. In addition to these lib files, three header files (*.h) are necessary for using levmar. They can be found in the clapack source folder (DIR_CLAPACK_SRC/INCLUDE). Namely: blaswrap.h, lapack.h, and f2c.h.
        8. Copy the four *.lib files and the three *.h files into a new directory called lapackblas which will become LAPACKBLAS_DIR.

        B: //Run Cmake to compile Levmar (levmar.lib)
        1. See the Levmar FAQ: We have to modify misc.h according to BLAS. Modify a few lines in misc.h:
        a. Uncomment line 31: ”#define LM_BLAS_PREFIX f2c_”
        b. Comment out line 37: “#define LM_BLAS_SUFFIX _ ”
        c. Uncomment line 36: “#define LM_BLAS_SUFFIX”.
        2. Modify misc.h, misc.c and misc_core.c from the Levmar directory by adding “#include ” at the top of each file. Also put a copy of blaswrap.h (from step 7 above) into the levmar source folder.
        3. Open CMAKE.
        4. Where is the source code: DIR_LEVMAR_SRC (levmar source folder)
        5. Where to build the binaries: DIR_LEVMAR_DST (ex. C:/Levmar) (your choice)
        6. Press Configure, choose you compiler again (Visual Studio 10 Win64)
        7. Change F2C_LIB_NAME to libf2c
        8. Set LAPACKBLAS_DIR to the previously defined directory (instead of using the default ‘/usr/lib’ you must point it to the folder you created in step 8 above containing the *.lib and *.h files).
        9. Make sure HAVE_LAPACK is ticked
        10. Press configure and generate
        11. Open LEVMAR.sln with Visual Studio and build the project for release. This should generate a levmar.lib file in the DIR_LEVMAR_DST\Release folder.

  2. Hey Charmie11, thanks for your replies which finally led me to my mistake: I didn’t add the three .h-files to the correct directory (which is in fact LAPACKBLAS_DIR and not the directory with the levmar source code).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s