0

I have been writing a c++ program in Ubuntu and window8 using armadillo. Under Windows8 the program compiles without problems.

The program is just using the linear systems solver.

Under Ubuntu the compiler says

"reference to `wrapper_dgels_' not defined"

The compiler line I use is:

mpic++ -O2 -std=c++11 -Wall -fexceptions -O2 -larmadillo -llapack -lblas program.o

However, right before the error I see:

g++ module_of_the_error.o

Which is something I haven't set.

I am using code blocks in Ubuntu, and I compiled armadillo with all the libraries that cmake asked. (BLAS< LAPACK, OpenBLAS, HDF5, ARPACK, etc)

I have no clue what might be causing the problem, since the exact same code compiles in visual studio.I have tried the compiler line modifications suggested but it does not seem to work.

Any help is appreciated.

2 Answers 2

4

This is one trap I fell into myself one time. You will not like the likely cause of your error.

The order of the arguments to the linker matters.

Instead of

mpic++ -O2 -std=c++11 -Wall -fexceptions -O2 -larmadillo -llapack -lblas program.o

try:

mpic++ -O2 -std=c++11 -Wall -fexceptions -O2 program.o -larmadillo -llapack -lblas

I.e., put the object files to be linked into the executable before the libraries.

By the way, at this stage you are only linking files that have already been compiled. It is not necessary to repeat command line options that are only relevant for compiling. So this will be equivalent:

mpic++ program.o -larmadillo -llapack -lblas

Moreover, depending on how you installed Armadillo, you are adding either one or two superfluous libraries in that line. One of the following should be enough:

mpic++ program.o -larmadillo

or

mpic++ program.o -llapack -lblas
1

EDIT: as the answer by rerx states, the problem is probably just a simple ordering of the switches/arguments supplied to g++. All the -l switches need to be after the -o switch. Or in other words, put the -o switch before any -l switches. For example:

g++ prog.cpp -o prog -O3 -larmadillo

original answer:

Looks like your compiler can't find the Armadillo run-time library. The proper solution is to specify the path for armadillo run-time library using the -L switch. For example, g++ -O2 blah.cpp -o blah -L /usr/local/lib/ -larmadillo

Another possible solution is to define ARMA_DONT_USE_WRAPPER before including the armadillo header, and then directly link with LAPACK and BLAS. For example:

#define ARMA_DONT_USE_WRAPPER
#include <armadillo>

More details are available at the Armadillo frequently asked questions page.

3
  • Thanks, but Still not working... This is ridiculously complicated, I think I'll use eigen instead... Commented Aug 25, 2014 at 18:24
  • Come on, this is not that hard. You'll need to figure this out anyway if you're going to link with any external library, such as OpenCV, or nlopt, etc. It also looks like it's a simple matter of getting the linking order right: put all the -l switches after the -o switch: g++ prog.cpp -o prog -O2 -larmadillo
    – mtall
    Commented Aug 26, 2014 at 1:43
  • Well, the problem is that codeblocks (and netbeans with c++ as well) put the arguments next to the g++ statement and not after the program.o. So if you tell me how to do that I can try to put the arguments after, otherwise I have no idea how to force the IDE to send the compiling order like that. Commented Aug 26, 2014 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.