forum.alglib.nethttp://forum.alglib.net/ Compile and link alglib library with new codehttp://forum.alglib.net/viewtopic.php?f=2&t=3761 Page 1 of 1

 Author: shaun22 [ Sat Jul 16, 2016 4:18 am ] Post subject: Compile and link alglib library with new code Hi,I just found out about alglib and wanted it give it a shot to a problem of spline fitting using constrained least squares optimization that I'm working on. I downloaded all the source code and took the example of lsfit_d_lin to get an introduction to the compilation and linking process. Here is the code: Code:#include #include #include #include "ap.h"#include "alglibinternal.h"#include "alglibmisc.h"#include "diffequations.h"#include "dataanalysis.h"#include "fasttransforms.h"#include "integration.h"#include "interpolation.h"#include "linalg.h"#include "optimization.h"#include "solvers.h"#include "specialfunctions.h"#include "statistics.h"#include "stdafx.h"using namespace alglib;int main(int argc, char **argv){    //    // In this example we demonstrate linear fitting by f(x|a) = a*exp(0.5*x).    //    // We have:    // * y - vector of experimental data    // * fmatrix -  matrix of basis functions calculated at sample points    //              Actually, we have only one basis function F0 = exp(0.5*x).    //    real_2d_array fmatrix = "[[0.606531],[0.670320],[0.740818],[0.818731],[0.904837],[1.000000],[1.105171],[1.221403],[1.349859],[1.491825],[1.648721]]";    real_1d_array y = "[1.133719, 1.306522, 1.504604, 1.554663, 1.884638, 2.072436, 2.257285, 2.534068, 2.622017, 2.897713, 3.219371]";    ae_int_t info;    real_1d_array c;    lsfitreport rep;    //    // Linear fitting without weights    //    lsfitlinear(y, fmatrix, info, c, rep);    printf("%d\n", int(info)); // EXPECTED: 1    printf("%s\n", c.tostring(4).c_str()); // EXPECTED: [1.98650]    //    // Linear fitting with individual weights.    // Slightly different result is returned.    //    real_1d_array w = "[1.414213, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]";    lsfitlinearw(y, w, fmatrix, info, c, rep);    printf("%d\n", int(info)); // EXPECTED: 1    printf("%s\n", c.tostring(4).c_str()); // EXPECTED: [1.983354]    return 0;}I am using 64-bit Ubuntu 14.04 and also installed libalglib-dev and libalglib3.8 that was available from the repositories. I used the following command to compile:Quote:g++ -g -Wall -I../src/ -L/usr/lib/x86_64-linux-gnu/ -lalglib linear.cpp But I end up with a bunch of linker errors:Quote:/tmp/ccrVBuSp.o: In function `main':/home/user/source/alglib/tests/linear.cpp:33: undefined reference to `alglib::real_2d_array::real_2d_array(char const*)'/home/user/source/alglib/tests/linear.cpp:34: undefined reference to `alglib::real_1d_array::real_1d_array(char const*)'/home/user/source/alglib/tests/linear.cpp:36: undefined reference to `alglib::real_1d_array::real_1d_array()'/home/user/source/alglib/tests/linear.cpp:37: undefined reference to `alglib::lsfitreport::lsfitreport()'/home/user/source/alglib/tests/linear.cpp:42: undefined reference to `alglib::lsfitlinear(alglib::real_1d_array const&, alglib::real_2d_array const&, long&, alglib::real_1d_array&, alglib::lsfitreport&)'/home/user/source/alglib/tests/linear.cpp:44: undefined reference to `alglib::real_1d_array::tostring(int) const'/home/user/source/alglib/tests/linear.cpp:50: undefined reference to `alglib::real_1d_array::real_1d_array(char const*)'/home/user/source/alglib/tests/linear.cpp:51: undefined reference to `alglib::lsfitlinearw(alglib::real_1d_array const&, alglib::real_1d_array const&, alglib::real_2d_array const&, long&, alglib::real_1d_array&, alglib::lsfitreport&)'/home/user/source/alglib/tests/linear.cpp:53: undefined reference to `alglib::real_1d_array::tostring(int) const'/home/user/source/alglib/tests/linear.cpp:50: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:37: undefined reference to `alglib::lsfitreport::~lsfitreport()'/home/user/source/alglib/tests/linear.cpp:36: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:34: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:54: undefined reference to `alglib::real_2d_array::~real_2d_array()'/home/user/source/alglib/tests/linear.cpp:50: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:37: undefined reference to `alglib::lsfitreport::~lsfitreport()'/home/user/source/alglib/tests/linear.cpp:36: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:34: undefined reference to `alglib::real_1d_array::~real_1d_array()'/home/user/source/alglib/tests/linear.cpp:54: undefined reference to `alglib::real_2d_array::~real_2d_array()'collect2: error: ld returned 1 exit statusCould someone help me with this? Also, if anyone has an example of using CMake to use with linking the alglib library and wouldn't mind sharing it, I'd appreciate it.Thanks,Shaun.

 Page 1 of 1 All times are UTC Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/