4

I cannot make Armadillo 4.3 work on Windows. The library armadillo/include is included and I run g++ "-LC:\\Armadillo\\BLAS_Lapack" -o1 -o test.exe test.o -llapack -lblas, then I get the following error message:

C:/Armadillo/include/armadillo_bits/blas_wrapper.hpp:183: undefined reference to `wrapper_ddot_'
test.o: In function `ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_':
C:/Armadillo/include/armadillo_bits/blas_wrapper.hpp:34: undefined reference to `wrapper_dgemv_'
test.o: In function `ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_':
C:/Armadillo/include/armadillo_bits/blas_wrapper.hpp:69: undefined reference to `wrapper_dgemm_'

If I run g++ -o1 -o test.exe test.o -llapack -lblas, I get

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -llapack
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lblas

I did uncomment the configuration file config.hpp according to the README file.

Does anybody know how to make Armadillo work? (I am using Eclipse CDT.)

MunHo
  • 81
  • 1
  • 1
  • 7
  • 2
    Did you copy the liblpack.a and libblas.a files to the lib folder of your MinGW installation? If you don't do that, you need to tell g++ (actually ld) which folder they're located in, via the `-L` or `--library-path` switch. You can see this if you type `ld --help` – enhzflep Jul 03 '14 at 09:30
  • @enhzflep When I downloaded Armadillo (and lapack) from [here](http://arma.sourceforge.net/download.html), there was no liblapck.a file neither libblas.a. Where do I find them? I did tell g++ where to look for lapack.lib and blas.lib using the `-L` switch though. – MunHo Jul 03 '14 at 10:31
  • Just downloaded Armadillo and had a look at the included files. I see that it contains pre-compiled libraries for x64 windows - albeit ones suitable for Visual Studio. In that case, I guess you've got a number of options. **1.** You can download the blas and lapack sources then build them yourself using minGW (download location is in the Readme.txt file) **2.** You could use the `dlltool` program that comes with mingw to generate the import lib from the DLL files that you do have. I've dont I know if this would even be a valid option, since the DLLs are x64 and you're using MinGW32. Try #1 – enhzflep Jul 03 '14 at 10:59
  • @enhzflep I built the sources and now have the liblapack.a and libblas.a files. I tried to link to them and to add the files to the lib folder of MinGW, both times without success. I still get the first error from my original post. – MunHo Jul 03 '14 at 12:27
  • Building the 2 libs or the test app isn't an option for me just now. Sorry, not sure _what_ the problem is. – enhzflep Jul 03 '14 at 15:21
  • @enhzflep After building the binaries of Lapack, there is a test one can run. When I run it all 98 tests but the last one are successful. Does that have anything to do with anything? – MunHo Jul 04 '14 at 07:40

3 Answers3

8

It took a while to get this right, but it seems transparent once it works. I will explain step by step. (Make sure you have uncommented the correct lines as directed in the README of the config.hpp file)

The general command for compiling with blas/lapack (using the default provided with armadillo (current version 4.500.0) and does make it faster :)

g++ main.cpp -I C:{ARMADILLO_ROOT}\include -L C:{ARMADILLO_ROOT}\examples\lib_win64 -lblas_win64_MT -llapack_win64_MT

where each of the commands are as follows:

  1. g++: GNU G++ Compiler (using MinGW 4.9.1 C++ from equationsolution.com)

  2. main.cpp: My main file of the C++ program (I have an abstract and concrete class defining the Levenshtein algorithm)

  3. -I C:{ARMADILLO_ROOT}\include: The GCC C++ Compiler Include Path (To include the Armadillo library) where ARMADILLO_ROOT is where you have decompressed and placed your armadillo files

  4. -L C:{ARMADILLO_ROOT}\examples\lib_win64: The MinGW C++ Linker Library Link Path (To link the BLAS and LAPACK libraries) I have used the default libs provided with armadillo, I believe and according to the doc you may and should substitute these linear libraries in a production instance)

  5. -lblas_win64_MT -llapack_win64_MT: Identify the libraries to be used (name must match, so you cannot put -lblas or -llapack UNLESS your files are named that way - by default in this armadillo version they are named blas_win64_MT lapack_win64_MT (win64 since I am using both a MinGW/C++ 64bit and a 64bit armadillo [they should match])

Following this logic, you may configure eclipse (using eclipse Luna R1 4.4.1 -should be the same procedure on other versions) with the following:

  • Right Click the Project and Select "Properties" item in the popup menu
  • Under "C/C++ Build" on the left menu Select "Settings"
  • Under "GCC C++ Compiler" click on "Includes (-I)" and add the include path C:{ARMADILLO_ROOT}\include (Screenshot1)
  • Under "MinGW C++ Linker" click on "Libraries" add each "Libraries (-l)" as named blas_win64_MT lapack_win64_MT. (Screenshot2)
  • Under the same "MinGW C++ Linker" click on "Libraries" add a "Library search path (-L)" C:{ARMADILLO_ROOT}\examples\lib_win64
  • Click the "Apply" button before pressing "OK"

--Screenshot1 Screenshot1

--Screenshot2 Screenshot2

snassr
  • 1,228
  • 14
  • 10
  • Thank you really. After days and days of searching this is what helped me get it to work. Appreciate taking the time to write such a detailed answer! – Mihai Aug 20 '18 at 07:47
3

It seems to work now! I am using the Lapack and BLAS from the webpage indicated in the Readme file that I compiled myself according to @enhzflep comments.

To link everything properly in Eclipse CDT right click on your project and go to properties, then:

  1. Under "C/C++ Build⟼Settings⟼GCC C++ Compiler⟼Command" type: g++ -I"C:\Armadillo\include" (replace with the correct path for your Armadillo folder). Make sure to do this for all Configurations (to be chosen in the drop-down menu at the top).
  2. Under "C/C++ Build⟼Settings⟼MinGW C++ Linker⟼Libraries" add lapack and blas to the Libraries.
  3. Under"C/C++ General⟼Paths and Symbols⟼GNU C++" add the path tot he include directory of your Armadillo folder C:\Armadillo\include.

It might be that it works with the original Lapack and BLAS files. It did not work for me, because I had only added the path to Armadillo under "C/C++ General⟼Paths and Symbols⟼GNU C++", which I guess only tells the editor what data types and functions to expect and not the compiler.

MunHo
  • 81
  • 1
  • 1
  • 7
2

If you're using MinGW on Windows, a good option is to use OpenBLAS with Armadillo. OpenBLAS provides optimized and multi-threaded implementations of BLAS and LAPACK: http://xianyi.github.io/OpenBLAS/

The OpenBLAS project provides pre-compiled versions for Windows. The source code can be also easily compiled under Linux and MacOS X.

Note that Armadillo doesn't support automatic installation under Windows. The cmake based installer provides a big fat warning message about that -- you're advised to heed it.

Instead of automatic installation, do the following (as described in the README.txt file that comes with Armadillo):

  1. Manually modify include/armadillo_bits/config.hpp to enable the use of BLAS and LAPACK. In other words, make sure that ARMA_USE_BLAS and ARMA_USE_LAPACK are uncommented (enabled).

  2. Also within include/armadillo_bits/config.hpp, disable ARMA_USE_WRAPPER, ie. make sure it's commented out.

  3. When compiling your C++ programs, tell your compiler to use the armadillo include folder directly, and link with openblas. For example, with gcc use the -I switch to specify the include folder.

mtall
  • 3,574
  • 15
  • 23
  • I did not find any precompiled versions for Windows on the link you posted. I followed the `README.txt` and don't think I have any problems including Armadillo, since the error message says: `In function `ZN4arma4blas3dotIdEET_jPKS2_S4_': C:/Armadillo/include/armadillo_bits/blas_wrapper.hpp:183: undefined reference to `wrapper_ddot_'`. I suspect that I am not able to link to Lapack and BLAS properly. – MunHo Jul 04 '14 at 07:47
  • If you're getting any errors with `wrapper_` in front, it means you still have `ARMA_USE_WRAPPER` enabled. Disable it, as explained above. Also, the link to precompiled version of OpenBLAS is on that page, under _Binary Packages_. It points to: http://sourceforge.net/projects/openblas/files/ – mtall Jul 04 '14 at 14:50