Author Topic: Third-party libraries: adding GSL to CODE::blocks  (Read 29330 times)

Offline humesit

  • Single posting newcomer
  • *
  • Posts: 4
Third-party libraries: adding GSL to CODE::blocks
« on: November 03, 2008, 01:38:22 pm »
hello

i´m  a student and quite new to c++, but worked with other languages. i use winXP and codeblocks 8.02...
my problem is, that i want to use the gsl (GNU scientific libaryhttp://www.gnu.org/software/gsl/) in my program.

how do i install it? i read the advices for other third party libarys in the wiki. not enough explanation for me...:-(

i downloaded the compressed file, what next? i tried to include the .c files by myself but that didn´t work.
(like that:)
Code
 
    #include <stdio.h>
     #include <gsl/specfunc/gsl_sf_bessel.h>  //i told the compiler to search for it, with "search directorys"

     int
     main (void)
     {
       double x = 5.0;
       double y = gsl_sf_bessel_J0 (x);
       printf ("J0(%g) = %.18e\n", x, y);
       return 0;
     }

error::
mingw32-g++.exe: no input files



thanks for every help!


best
chris

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #1 on: November 03, 2008, 01:54:01 pm »
If there are no prebuild libraries, you have to build them yourselves, and add the libraries in the "Linker settings" and the path, where they are installed in the linkers "Search directories".

How the libraries can be build should be explained in a "Readme"-file, or something similar (the exact way depends very much on the libs you want to use).
But your error message seems to be caused by something different, because missing libs normally cause an "undefined reference" error (this error might come up later).

Please turn on full commandline logging and post the appropriate part of the build log:

change "Settings -> Compiler and debugger... -> Global compiler settings -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline"

Offline ASJ

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #2 on: November 03, 2008, 01:56:10 pm »
gsl is just a library you can link to. Just make sure your headers and libraries can be found. Judging on the error message, I get the impression that you just opened some .cpp file instead of creating a project and adding the code to that project.
Just create a new project, and copy the code in the the main.cpp file and try again....it should compile then

Offline humesit

  • Single posting newcomer
  • *
  • Posts: 4
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #3 on: November 03, 2008, 02:16:55 pm »
well. you're both right. i just used a .cpp file instead of a project.

so far. but when i just link to the libary - there will be some trouble finding the next  #include(d) files he finds in the first .h file.

so i have to try this built thing.

INSTALL.dat:
Quote
After unpacking the distribution
the Makefiles can be prepared using the configure command,

  ./configure

You can then build the library by typing,

  make

how can i use the command line of windows to built my libary?

thanks chris

[attachment deleted by admin]
« Last Edit: November 03, 2008, 02:19:34 pm by humesit »

Offline ASJ

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #4 on: November 03, 2008, 03:01:08 pm »
if you're working on windows probably the easiest thing to get started is to use pre-compiled libraries.
If you are using the mingw compiler things just download the appropriate packages from gnuwin32 at sourceforge..
For the microsoft compilers I am not sure where to find pre compiled packages...

Offline humesit

  • Single posting newcomer
  • *
  • Posts: 4
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #5 on: November 03, 2008, 03:41:09 pm »
sry the actual pre-compiled libary of gsl is version 1.1, whereas actal version of gsl is 1.8... :?

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576

Offline nenin

  • Almost regular
  • **
  • Posts: 202
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #7 on: November 03, 2008, 04:46:00 pm »
You should use msys to build GSL under Win. There are no problems at all. Start msys, cd to gsl folder, run configure with options (like CPU tune), than run make. After all you got set of *.a files in gsl-1.10/.lib folder. Than copy appropriate libs (libgsl.a) to mingw/lib/gsl and header from gsl-1.10/gsl to mingw/include. May be, it will be necessary to copy libgslcblas.a as well.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #8 on: November 03, 2008, 05:35:17 pm »
Few tips:

1) To build dll of GSL, add -mno-undefined to LDFLAGS while compiling. Correct sequence of commands can be-
Code
./configure --enable-shared --prefix=/mingw
make LDFLAGS=-mno-undefined

2) If possible use cross-compiler to build GSL. From my experience, compiling GSL under MSYS is 2-3 times slower than a cross-compilation.
Be a part of the solution, not a part of the problem.

Offline nenin

  • Almost regular
  • **
  • Posts: 202
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #9 on: November 03, 2008, 11:41:41 pm »
Few tips:
<****>
2) If possible use cross-compiler to build GSL. From my experience, compiling GSL under MSYS is 2-3 times slower than a cross-compilation.
It is necessary ~ 2 times per year.  :wink:

Offline humesit

  • Single posting newcomer
  • *
  • Posts: 4
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #10 on: November 04, 2008, 05:15:18 am »
ok i just downloaded the pre-compiled libraries 1.8 version  from sourceforge! thanks for that.
i added the \include directory to the searchdirectory of my compiler under "compiler and debugger"
but no he can´t find the functions that are declared in these .h files there.

this is a simply example for the use of gsl, copied from the documentation.
Code
    #include <stdio.h>
     #include <gsl/gsl_sf_bessel.h>

     int
     main (void)
     {
       double x = 5.0;
       double y = gsl_sf_bessel_J0(x);

        printf ("J0(%g) = %.18e\n", x, y);
       return 0;
     }
Code
buid message:
obj\Debug\main.o||In function `main':|
C:\test\besseltest2\main.cpp|8|undefined reference to `_gsl_sf_bessel_J0'|
||=== Build finished: 1 errors, 0 warnings ===|

build log:
mingw32-g++.exe -Wall -fexceptions  -g    -IC:\Programme\GnuWin32\include  -c C:\test\besseltest2\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\Programme\GnuWin32\include  -o bin\Debug\besseltest2.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/test/besseltest2/main.cpp:8: undefined reference to `_gsl_sf_bessel_J0'
collect2: ld returned 1 exit status



thanks for all the help. i´m a german student, currently studying in china near shanghai.
there is no help from the students/profs here and it certainly wasn`t my idea to use C++. :?

digital19

  • Guest
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #11 on: November 04, 2008, 06:44:10 am »
I had the same problem.

For me, I had to add 'libgsl.a' to the link libraries in "Linker Settings".

Offline nenin

  • Almost regular
  • **
  • Posts: 202
Re: Third-party libraries: adding GSL to CODE::blocks
« Reply #12 on: November 04, 2008, 09:26:29 pm »
I had the same problem.

For me, I had to add 'libgsl.a' to the link libraries in "Linker Settings".
For sure, you always must to add libgsl.a (and sometimes, libgslcblas.a) to "Link libraries:"