Author Archives: Patrick M. Kelly

Installing MLPACK on Windows 10 using Cygwin

After spending far too many hours trying to get mlpack installed under Windows using Cygwin, I wanted to document a simple change that finally made it work for me.

In order to get mlpack to compile correctly, you first need to install (A) the boost development library; and (B) the Armadillo linear algebra library. The boost development library (libboost-devel) can be installed directly from the Cygwin installation program. Armadillo can be downloaded from sourceforge, and I was able to install it without difficulty.

The most frustrating problem came when I tried the actual build for mlpack. The process started out fine, but after a while it failed at the linking stage for executables. It was generating error messages related to undefined references, and including the following ominous note:

[...] relocation truncated to fit: R_X86_64_PC32 against undefined symbol [...]

I’d never seen that error before and had no idea what to do about it. Looking for a solution caused nothing but pain and frustration. The most promising leads were suggesting that I may need to specify a larger memory model when compiling (using the flag -mcmodel on g++). It didn’t work. I tried numerous changes somewhat blindly: different compiler flags, cleaning and rebuilding from scratch, etc. I even installed the 32-bit version of Cygwin in the hopes that the 64-bit version was the source of my problem. It wasn’t.

Here are some of the actual error messages enountered:

[ 24%] Linking CXX executable ../../../../bin/mlpack_preprocess_describe.exe
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text+0x12cd): undefined reference to `mlpack::util::PrefixedOutStream::operator<<(std::ostream& (*)(std::ostream&))'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text+0x12cd): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `mlpack::util::PrefixedOutStream::operator<<(std::ostream& (*)(std::ostream&))'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamISsEERT_RKSs[_ZN6mlpack3CLI8GetParamISsEERT_RKSs]+0x2e): undefined reference to `mlpack::CLI::GetSingleton()'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamISsEERT_RKSs[_ZN6mlpack3CLI8GetParamISsEERT_RKSs]+0x2e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `mlpack::CLI::GetSingleton()'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamISsEERT_RKSs[_ZN6mlpack3CLI8GetParamISsEERT_RKSs]+0x3d): undefined reference to `mlpack::CLI::GetSingleton()'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamISsEERT_RKSs[_ZN6mlpack3CLI8GetParamISsEERT_RKSs]+0x3d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `mlpack::CLI::GetSingleton()'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamIiEERT_RKSs[_ZN6mlpack3CLI8GetParamIiEERT_RKSs]+0x22): undefined reference to `mlpack::CLI::GetSingleton()'
CMakeFiles/mlpack_preprocess_describe.dir/preprocess_describe_main.cpp.o:preprocess_describe_main.cpp:(.text$_ZN6mlpack3CLI8GetParamIiEERT_RKSs[_ZN6mlpack3CLI8GetParamIiEERT_RKSs]+0x22): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `mlpack::CLI::GetSingleton()'

So how did I resolve this issue? I disabled the use of shared libraries and used static libraries instead. Admittedly this is more of a workaround than a solution, but it worked. And it was not at all obvious to me that I should try doing that, given my line of thinking related to the error message above.

In the top-level directory for mlpack, I simply edited the following line in CMakeLists.txt and turned the option for shared libraries OFF rather than leaving it turned ON.

option(BUILD_SHARED_LIBS
    "Compile shared libraries (if OFF, static libraries are compiled)." OFF)

Once I changed that flag and started a clean build, everything worked fine.