forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 8:52 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: ALGLIB under windows Code::blocks
PostPosted: Wed Sep 07, 2016 6:02 pm 
Offline

Joined: Wed Sep 07, 2016 5:56 pm
Posts: 4
Hi to all,
-I am a total newbie for C++ in general. I wanted to install ALGLIB under Codeblocks, but I made clearly a mistake I am not able to find.

Under Windows 10,
I installed "codeblocks-16.01mingw-setup" under the C:/codeblocks dir.
Then I extracted "alglib-3.10.0.cpp.gpl" to a dir that I called "C:\clibs\prova4".
I created a c++ project named prova4 in the dir "C:\clibs\prova4"
my dirlist is :

Directory di C:\clibs\prova4
07/09/2016 19:32 <DIR> .
07/09/2016 19:32 <DIR> ..
07/09/2016 18:45 1,851,664 alglibinternal.cpp
06/09/2016 14:09 36,101 alglibinternal.h
06/09/2016 14:09 183,193 alglibmisc.cpp
06/09/2016 14:09 49,863 alglibmisc.h
06/09/2016 14:09 324,544 ap.cpp
06/09/2016 14:09 60,142 ap.h
07/09/2016 19:16 <DIR> bin
06/09/2016 14:09 1,307,516 dataanalysis.cpp
06/09/2016 14:09 307,205 dataanalysis.h
06/09/2016 14:09 39,430 diffequations.cpp
06/09/2016 14:09 9,823 diffequations.h
06/09/2016 14:09 118,494 fasttransforms.cpp
06/09/2016 14:09 25,643 fasttransforms.h
06/09/2016 14:09 136,763 integration.cpp
06/09/2016 14:09 31,907 integration.h
06/09/2016 14:09 1,343,313 interpolation.cpp
06/09/2016 14:09 307,623 interpolation.h
06/09/2016 14:09 1,557,964 linalg.cpp
06/09/2016 14:09 334,967 linalg.h
07/09/2016 19:07 956 lista.txt
07/09/2016 19:32 553 main.cpp
07/09/2016 19:16 <DIR> obj
06/09/2016 14:09 1,378,551 optimization.cpp
06/09/2016 14:09 277,932 optimization.h
07/09/2016 19:23 1,145 prova4.cbp
07/09/2016 19:23 357 prova4.layout
06/09/2016 14:09 500,564 solvers.cpp
06/09/2016 14:09 170,881 solvers.h
06/09/2016 14:09 291,595 specialfunctions.cpp
06/09/2016 14:09 63,975 specialfunctions.h
06/09/2016 14:09 611,974 statistics.cpp
06/09/2016 14:09 56,959 statistics.h
06/09/2016 14:09 4 stdafx.h
31 File 11,381,601 byte
4 Directory 18,978,639,872 byte disponibili


I instructed the project linker in codeblocks to point to "C:\clibs\prova4".

my main.cpp code is:

Code:
#include <iostream>
#include <stdio.h>
#include "alglibinternal.h"
#include "alglibmisc.h"
#include <ap.h>
#include "dataanalysis.h"
#include "diffequations.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 std;

int main()
{
alglib::real_1d_array x;
x = "[1,2,3,4,5]";

  //  std::cout << "Hello world!" << std::endl;
    return 0;
}

When I try to build it I get:

mingw32-g++.exe -Wall -fexceptions -g -IC:\clibs\prova4\ -IC:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include -IC:\clibs\cpp\src -c C:\clibs\prova4\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\CodeBlocks\MinGW\lib\cpp\src -o bin\Debug\prova4.exe obj\Debug\main.o
obj\Debug\main.o: In function `main':
C:/clibs/prova4/main.cpp:22: undefined reference to `alglib::real_1d_array::real_1d_array()'
C:/clibs/prova4/main.cpp:23: undefined reference to `alglib::real_1d_array::real_1d_array(char const*)'
C:/clibs/prova4/main.cpp:23: undefined reference to `alglib::real_1d_array::operator=(alglib::real_1d_array const&)'
C:/clibs/prova4/main.cpp:23: undefined reference to `alglib::real_1d_array::~real_1d_array()'
C:/clibs/prova4/main.cpp:26: undefined reference to `alglib::real_1d_array::~real_1d_array()'
C:/clibs/prova4/main.cpp:23: undefined reference to `alglib::real_1d_array::~real_1d_array()'
C:/clibs/prova4/main.cpp:26: undefined reference to `alglib::real_1d_array::~real_1d_array()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
8 error(s), 0 warning(s) (0 minute(s), 1 second(s))



When I change "ap.h" to ap.cpp I obtain:

-------------- Build: Debug in prova4 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -IC:\clibs\prova4\ -IC:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include -IC:\clibs\cpp\src -c C:\clibs\prova4\main.cpp -o obj\Debug\main.o
In file included from C:\clibs\prova4\main.cpp:5:0:
C:\clibs\prova4/ap.cpp:143:17: warning: 'alglib_impl::_ae_bool_must_be_8_bits_wide' defined but not used [-Wunused-variable]
static char _ae_bool_must_be_8_bits_wide[1-2*((int)(sizeof(ae_bool))-1)*((int)(sizeof(ae_bool))-1)];
^
C:\clibs\prova4/ap.cpp:144:13: warning: 'alglib_impl::_ae_int32_t_must_be_32_bits_wide' defined but not used [-Wunused-variable]
static char _ae_int32_t_must_be_32_bits_wide[1-2*((int)(sizeof(ae_int32_t))-4)*((int)(sizeof(ae_int32_t))-4)];
^
C:\clibs\prova4/ap.cpp:145:13: warning: 'alglib_impl::_ae_int64_t_must_be_64_bits_wide' defined but not used [-Wunused-variable]
static char _ae_int64_t_must_be_64_bits_wide[1-2*((int)(sizeof(ae_int64_t))-8)*((int)(sizeof(ae_int64_t))-8)];
^
C:\clibs\prova4/ap.cpp:146:13: warning: 'alglib_impl::_ae_int_t_must_be_pointer_sized' defined but not used [-Wunused-variable]
static char _ae_int_t_must_be_pointer_sized [1-2*((int)(sizeof(ae_int_t))-(int)sizeof(void*))*((int)(sizeof(ae_int_t))-(int)(sizeof(void*)))];
^
mingw32-g++.exe -LC:\CodeBlocks\MinGW\lib\cpp\src -o bin\Debug\prova4.exe obj\Debug\main.o
Output file is bin\Debug\prova4.exe with size 1.46 MB
Process terminated with status 0 (0 minute(s), 3 second(s))
0 error(s), 4 warning(s) (0 minute(s), 3 second(s))


but if I insert a line:

Code:
alglib::samplemean(x);


I obtain:
------------- Build: Debug in prova4 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -IC:\clibs\prova4\ -IC:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include -IC:\clibs\cpp\src -c C:\clibs\prova4\main.cpp -o obj\Debug\main.o
In file included from C:\clibs\prova4\main.cpp:5:0:
C:\clibs\prova4/ap.cpp:143:17: warning: 'alglib_impl::_ae_bool_must_be_8_bits_wide' defined but not used [-Wunused-variable]
static char _ae_bool_must_be_8_bits_wide[1-2*((int)(sizeof(ae_bool))-1)*((int)(sizeof(ae_bool))-1)];
^
C:\clibs\prova4/ap.cpp:144:13: warning: 'alglib_impl::_ae_int32_t_must_be_32_bits_wide' defined but not used [-Wunused-variable]
static char _ae_int32_t_must_be_32_bits_wide[1-2*((int)(sizeof(ae_int32_t))-4)*((int)(sizeof(ae_int32_t))-4)];
^
C:\clibs\prova4/ap.cpp:145:13: warning: 'alglib_impl::_ae_int64_t_must_be_64_bits_wide' defined but not used [-Wunused-variable]
static char _ae_int64_t_must_be_64_bits_wide[1-2*((int)(sizeof(ae_int64_t))-8)*((int)(sizeof(ae_int64_t))-8)];
^
C:\clibs\prova4/ap.cpp:146:13: warning: 'alglib_impl::_ae_int_t_must_be_pointer_sized' defined but not used [-Wunused-variable]
static char _ae_int_t_must_be_pointer_sized [1-2*((int)(sizeof(ae_int_t))-(int)sizeof(void*))*((int)(sizeof(ae_int_t))-(int)(sizeof(void*)))];
^
mingw32-g++.exe -LC:\CodeBlocks\MinGW\lib\cpp\src -o bin\Debug\prova4.exe obj\Debug\main.o
obj\Debug\main.o: In function `main':
C:/clibs/prova4/main.cpp:24: undefined reference to `alglib::samplemean(alglib::real_1d_array const&)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
2 error(s), 4 warning(s) (0 minute(s), 3 second(s))


I've been struggling for days, but I think I need help, since this is my first c++ attempt..
thanks a lot..


Top
 Profile  
 
 Post subject: Re: ALGLIB under windows Code::blocks
PostPosted: Fri Sep 09, 2016 9:41 pm 
Offline

Joined: Wed Sep 07, 2016 5:56 pm
Posts: 4
Please, any suggestion before I give up??


Top
 Profile  
 
 Post subject: Re: ALGLIB under windows Code::blocks
PostPosted: Sat Sep 10, 2016 11:45 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Hello!

It is not ALGLIB problem - you do not understand modular structure of C++ programs. A program is a set of C++ files, which must be compiled separately. You should add to your project tree all cpp files from ALGLIB directory, so that codeblocks knows about these files and compiles them as well as you main.cpp

If you want to reference a function from other cpp file, you should include header file with its declaration - but not cpp file, not implementation.


Top
 Profile  
 
 Post subject: Re: ALGLIB under windows Code::blocks
PostPosted: Sat Sep 10, 2016 1:59 pm 
Offline

Joined: Wed Sep 07, 2016 5:56 pm
Posts: 4
Thank you Sergei, surely I'm a total newbie for C++.
Still, I tried to understand a bit before declaring I was not able to solve the problem. I included a copy of my project directory in the post to show you that I had all the cpp files and the h files in the project directory. I first included only all the h files in the declaration of the main.cpp header, but I had to include also the ap.cpp to have a correct 1d array. Still, statistics.cpp gives alway errors, whatever I include only .h or also .cpp. I also get errors in compiling manually with:
Code:
g++ *.cpp -o main
. Could you please have a look at the errors that I posted to help me?? Thanks again..


Top
 Profile  
 
 Post subject: Re: ALGLIB under windows Code::blocks
PostPosted: Sun Sep 11, 2016 3:07 pm 
Offline

Joined: Wed Sep 07, 2016 5:56 pm
Posts: 4
I realized that "include the cpp files" meant include the cpp in the project, not include in the main.cpp header as .h files.
Now everything seems ok. Clearly I miss basic principles of c++ programming, but less criptic instructions for a beginner would be helpful for a quick start...
thank you again...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group