6

I am trying to install MLPack on windows 8. I configure 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 ran CMake I had a whole series of warning like these ones:

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 \mlpack-1.0.4\src\mlpack directory I found another CMakeLists file with:

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

that I changed to (not sure if that was a good idea):

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

then CMake seems to be running smoothly:

-- 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 when running make I have tons of 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 investigation seems to be related to Armadillo.

Any idea what is happening ? I guess I should use target_link_libraries for Armadillo but I am not sure how.

coatless
  • 20,011
  • 13
  • 69
  • 84
Vince
  • 3,979
  • 10
  • 41
  • 69
  • Yes, you definitely need target_link_libraries() to link to Armadillo in your own CMakeLists.txt. Can you post your full/relevant parts of CMakeLists.txt – Vaibhav Desai Apr 11 '13 at 03:43
  • Thx a lot. I wonder if I can really post the whole file, it is quite long. For the relevant parts, I just found a line with "find_package(Armadillo 2.4.2 REQUIRED)" and later a line with "include_directories(${ARMADILLO_INCLUDE_DIRS})". But I am real beginner, I might definitly miss something. The full files are here:http://www.mlpack.org/files/mlpack-1.0.4.tar.gz I just made the changes described in the post ... – Vince Apr 11 '13 at 04:01
  • add something like this: target_link_libraries(gmm.exe ${ARMADILLO_LIBRARIES}). See if this works. Or just use "gmm" instead of "gmm.exe" and try again – Vaibhav Desai Apr 11 '13 at 06:53
  • tried with .exe and cmake complains gmm.exe was not built with this project. Without .exe, cmake complains gmm was not built in this directory ... – Vince Apr 11 '13 at 07:30

3 Answers3

6

The issue is hopefully pretty easy to resolve. When you do this...

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

you're effectively short-circuiting the find_package(Armadillo 2.4.2 REQUIRED) call, since it expects to have to do the work to find these paths. However, when find_package does the work, the variable ARMADILLO_LIBRARY gets set to the path to the library itself - not the path to the lib's directory.

So the problem boils down to setting ARMADILLO_LIBRARY to the path to the lib's directory rather than the lib itself. This ultimately yields a linker error since the target gmm (added in src\mlpack\methods\gmm\CMakeLists.txt) links to mlpack, and mlpack has been set to link to ${ARMADILLO_LIBRARIES}, which isn't set correctly.

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

So to fix this, you should delete the lines setting ARMADILLO_LIBRARY and ARMADILLO_INCLUDE_DIR, and revert your change in src\mlpack\CMakeLists.txt (using link_directories is generally a bad idea anyway).

After making these changes, you should delete at least your CMakeCache.txt (in the root of your build tree), or even your entire build tree before re-running CMake to avoid the possibility of using bad cached values from previous failed attempts.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • Thx ! Tried this but I get this error: CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message): Could NOT find Armadillo: Found unsuitable version "0.0.0", but required is at least "2.4.2" (found C:/Program Files (x86)/armadillo/lib/libarmadillo.dll) ... could it be that my installation of armadillo is messed up somehow ? – Vince Apr 12 '13 at 00:24
  • Yes - probably. Are you using the same generator for MLPack as you did for compiling Armadillo? (MinGW?) It looks like the Armadillo lib is found correctly, but that it can't be read properly to find out its version. – Fraser Apr 12 '13 at 00:49
  • I compiled armadillo using cmake then mingw32-make install. Now, I just performed it again without any changes to the cmake files (except deleting cache and tree) and things went smoothly (same as when I did it a couple of days ago). Now I am not sure where I messed up last time, because after that using cmake for mlpack seems now satisfied with armadillo (detect version 3.800.2). But now I have warnings about libxml2 ("targets may link only to libraries"). Did not compile libxml2, just downloaded binaries ... might come from that ? (btw, super thx for the help) – Vince Apr 12 '13 at 02:17
  • We're getting there :-) You're not setting `LIBXML2_LIBRARIES` explicitly too are you? If so, it should probably also refer to the library rather than the folder the library's in. I don't use MinGW myself, but it looks like the Windows binaries for libxml2 are only suitable for use with MSVC, not MinGW. You'll need to build libxml2 with mingw32-make or maybe get it using mingw-get. Try googling for "libxml2 mingw" – Fraser Apr 12 '13 at 03:25
  • now struggling with libxml2 (http://stackoverflow.com/questions/16007716/gnuwin32-libxml2-installation-setting-several-lib-and-include-directories) ... will come back as soon as this is solved (arghhh). – Vince Apr 15 '13 at 04:51
  • now cmake seems to perform its duty well, finding everything and not complaining about anything. But now when I use mingw32-make to compile mlpack, at 32%, it displays "scanning dependencies of target det", has the computer computing like crazy, but with seemingly nothing going on. It has been one hour now, I guess something is wrong ... – Vince Apr 16 '13 at 02:33
5

I realize this is a late answer, and I hope you have it figured out by now. Even so, I believe your issue is that the ARMADILLO_LIBRARY variable should hold the exact location of the library, instead of the directory the library is in. So, maybe this would 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 should also contain the actual path of libxml2.lib (or whatever the actual library is called).

Have you seen this page of instructions I wrote a while back for compiling mlpack on Windows?

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

Feel free to file a bug report on Trac if you have further problems in the future. I only stumbled upon this by chance, so I don't monitor Stack Overflow for issues.

ryan
  • 839
  • 4
  • 13
3

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

#define ARMA_USE_LAPACK 
#define ARMA_USE_WRAPPER

in the file

include/armadillo_bits/config.hpp

which is in the armadillo source tree.

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

Kedar Grr
  • 53
  • 5