Linking Armadillo Libraries with CMake

I am trying to install MLPack on windows 8. I am configuring the CMakeLists.txt file with:

set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib") set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include") 

Then, when I started CMake, I had a whole series of warnings like these:

 WARNING: Target "mlpack" requests linking to directory "C:\Program Files (x86)\armadillo\lib". Targets may link only to libraries. CMake is dropping the item. 

In the \ mlpack-1.0.4 \ src \ mlpack directory, I found another CMakeLists file with:

 target_link_libraries(mlpack ${ARMADILLO_LIBRARIES} ${Boost_LIBRARIES} ${LIBXML2_LIBRARIES} ) 

what I changed (not sure if it was a good idea):

 target_link_libraries(mlpack ${Boost_LIBRARIES} ) link_directories(mlpack ${ARMADILLO_LIBRARIES} ${LIBXML2_LIBRARIES} ) 

then CMake works fine:

 -- Found Armadillo: C:\Program Files (x86)\armadillo\lib (found suitable version "3.800.2", minimum required is "2.4.2") -- Found LibXml2: C:\cpp\libraries\libxml2-2.7.8.win32\lib (found suitable version "2.7.8", minimum required is "2.6.0") -- Boost version: 1.53.0 -- Found the following Boost libraries: -- program_options -- unit_test_framework -- Boost version: 1.53.0 -- Found the following Boost libraries: -- random -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- Configuring done -- Generating done -- Build files have been written to: C:/cpp/libraries/mlpack-1.0.4 

but now at startup I have many such errors:

 Linking CXX executable ..\..\..\..\gmm.exe CMakeFiles\gmm.dir/objects.a(gmm_main.cpp.obj):gmm_main.cpp:(.text+0xb9): undefined reference to `wrapper_dgemv_' CMakeFiles\gmm.dir/objects.a(gmm_main.cpp.obj):gmm_main.cpp:(.text$_ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb[__ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb]+0x115): undefined reference to `wrapper_dgetrf_' 

which, after research, seems to be related to Armadillo.

Any idea what is going on? I assume I should use target_link_libraries for Armadillo, but I'm not sure how to do this.

+4
source share
3 answers

The problem, I hope, is quite easily resolved. When you do this ...

 set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib") set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include") 

you effectively close the call to find_package(Armadillo 2.4.2 REQUIRED) , since it expects it to do the job to find these paths. However, when find_package does the work, the ARMADILLO_LIBRARY variable ARMADILLO_LIBRARY set to the path to the library itself, and not to the path to the lib directory.

Thus, the problem boils down to setting the ARMADILLO_LIBRARY path to the lib directory, not lib itself. This ultimately leads to a linker error, since the target gmm (added to src \ mlpack \ methods \ gmm \ CMakeLists.txt) is linked to mlpack , and mlpack set to link to ${ARMADILLO_LIBRARIES} , which isn’t correct.

It turns out that find_package(Armadillo ...) already checks in "$ENV{ProgramFiles}/Armadillo/lib" and "$ENV{ProgramFiles}/Armadillo/include" , and I expect this solution to be "C:\\Program Files (x86)\\armadillo\\lib" and "C:\\Program Files (x86)\\armadillo\\include" on your computer.

So, to fix this, you should remove the lines setting ARMADILLO_LIBRARY and ARMADILLO_INCLUDE_DIR and return your change to src \ mlpack \ CMakeLists.txt (using link_directories is usually a bad idea).

After making these changes, you should delete at least your CMakeCache.txt (at the root of the assembly tree) or even the entire assembly tree before starting CMake again to avoid the possibility of using invalid cached values ​​from previous failed attempts.

+5
source

I understand that this is a late answer, and I hope you already understood it. However, I believe that your problem is that the variable ARMADILLO_LIBRARY should contain the exact location of the library, and not the directory in which the library is located. So maybe this will work:

 set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib\\armadillo.lib") set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include") 

The variable LIBXML2_LIBRARIES must also contain the actual path to libxml2.lib (or whatever is called by the actual library).

Did you see this page of instructions that I wrote some time ago to compile mlpack on Windows?

http://www.mlpack.org/trac/wiki/MLPACKOnWindows

Feel free to write a bug report to Trac if you have any further problems in the future. I accidentally stumbled upon this, so I do not control Stack for problems.

+5
source

I ran into the same problem. There are two aramadillo library faq bullets that ask you to uncomment the lines

 #define ARMA_USE_LAPACK #define ARMA_USE_WRAPPER 

in file

 include/armadillo_bits/config.hpp 

which is in the source tree.

When you recompile after a line break, you can see the symbols in the / dll armadillo shared library. Hope this helps!

+3
source

All Articles