0

I'm trying to compile a program which uses the alglib function pearsoncorr2.

Unfortunately I always get compilation errors like the following:

undefined reference to `alglib::real_1d_array::real_1d_array()'

I know that I have to compile all the dependencies of the alglib unit which contains the function I want to use. In my case it's statistics.h. I'm including all the necessary files (ap.h, statistics.h, alglibinternal.h, alglibmisc.h, linalg.h, specialfunctions.h) when compiling my program, but still I get these undefined reference errors.

I'm using g++ on linux.

What am I doing wrong?

Thanks in advance.

Jenia
  • 3
  • 1
  • 2

2 Answers2

0

Alglib needs to compile all 13 cpp files before using it.

I have CMakeList.txt to tare care all the dependencies for me.

Jet
  • 11
0

You also need to include the binary part -- i.e., either the *.o files or the *.so library file -- on your final link line. So for example, you probably need to link with linalg.o .

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • I don't have the o-files. I tried to compile the cpp files belonging to the h-files mentioned above, but that won't work. – Jenia Aug 17 '11 at 13:41
  • I have never used `alglib`, but I took a quick look at the website. They certainly seem to suggest that one common way of using the library is to add (some of) their `*.cpp` files to your project and just compile them along with your source; one of those files defines that missing constructor (and presumably others define other things you need as well.) What do you mean it won't work? – Ernest Friedman-Hill Aug 17 '11 at 13:46
  • I already included the respective h-files as headers in my main source. So they should be compiled when I compile my main source. Or am I missing something? – Jenia Aug 17 '11 at 14:10
  • `*.h` files include the declarations of classes, and the definitions of inline functions; other functions are defined in the `*.cpp` files and unless you include those in the linked application, then you'll get errors like you're getting here. Including the `*.h` files when you compile your own source does *not* in any way cause the code in any corresponding `*.cpp` files to be included in the final application. – Ernest Friedman-Hill Aug 17 '11 at 14:12
  • 1
    It's working now. I did not include the cpp - files in the first place. So both the cpp files and the h-files have to be included. Thank you very much for your help. – Jenia Aug 17 '11 at 14:24