I want to use the mathematical library GSL wth DEV C++.
But gives a error: [Linker error] undefined reference to `gsl_sf_bessel_j_0'
ld returned 1 exit status
C:\Dev-Cpp\projetos\Makefile.win [Build Error][Projeto1.exe] Error 1
include <stdio.h>
include <gsl/gsl_sf_bessel.h>
int main()
{
double x=6;
double y = gsl_sf_bessel_j_0(6);
printf("J0(%g)=%.18e\n",x,y);
return 0;
}
Anyone know how to fix it?
thks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I copied and pasted your program and got it to work. Here is a copy of the compiler log so you know what it is suppose to look like and understand what Clifford is asking you.
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Projects\Makefile.win" all
gcc.exe main.o -o "Projeto1.exe" -L"C:/Dev-Cpp/lib" -lgsl
Execution terminated
Compilation successful
I also was able to almost recreate your compiler log simply by leaving out the link to the gsl library (see it is included above as -lgsl).
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Projects\Makefile.win" all
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"
I think you missed the point, no where in the compile log does it show the library being included. On the tool bar go to Project>>Project Options. When the Project Options dialog comes up go to the Parameters tab, in the linker column far right, have you explicitly added your library there? If not then do so.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stupid question of the day, but you didn't state that you did this.
Did you include the GSL library in your project? I don't mean the header file, I mean the library itself. I don't have the GSL installed on this computer so I can't tell you exactly what you need to include, but did you include the gsl.a library? You would have added it to the linker options and it would look something like: -lgsl ????
See Ya
Butch
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is a section in the thread titled "Please Read Before Posting a Question" on the compile log, including headers, and linking libraries that you may want to check out. It goes into some of the mechanics of the process.
As Clifford and Butch have pointed out, if you want to use a library, you MUST specifically link that library to your executable. You can do it either by the process that Clifford indicated, or the somewhat more old fashioned way (a personal favorite) that Butch laid out (familar to those who are used to doing things from the command line). It is not enough to have the library in the search path.
If you do a bit of searching on GSL here in the forum, you will probably stumble across some work I did several years ago.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That is not what I asked. Your log clearly shows that you have not linked the library at all. I don't mean installed teh library, or included teh header but linked the library.
invokes the linker. You have not specified the library, or the library's location. That is how I know, and why the log is necessary. The link you posted even discusses "compiling and linking", and shows you what the command line should look like (albeit for a different platform and so slightly different to what is needed here).
First of all you need to determine where your libgsl.a file is. If it is not in C:/Dev-Cpp/lib (and I recommend not putting it there BTW), then you need to add the path in Project|Project options|Directories|Library Directories. Next in Project|Project options|Parameters|Linker, add -lgsl (that is -<lowercase-L>gsl not a <one> or anything else). You may need to add other libraries such as -lgslblas for example. You do not need to add -lm (the standard math library) as suggested in teh documentation you linked to, since this is a default library. and will be linked in any case.
>> either by the process that Clifford indicated
That was BiT actually, not me.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to use the mathematical library GSL wth DEV C++.
But gives a error:
[Linker error] undefined reference to `gsl_sf_bessel_j_0'
ld returned 1 exit status
C:\Dev-Cpp\projetos\Makefile.win [Build Error] [Projeto1.exe] Error 1
include <stdio.h>
include <gsl/gsl_sf_bessel.h>
int main()
{
}
Anyone know how to fix it?
thks
Hi Everyone:
I copied and pasted your program and got it to work. Here is a copy of the compiler log so you know what it is suppose to look like and understand what Clifford is asking you.
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Projects\Makefile.win" all
gcc.exe main.o -o "Projeto1.exe" -L"C:/Dev-Cpp/lib" -lgsl
Execution terminated
Compilation successful
I also was able to almost recreate your compiler log simply by leaving out the link to the gsl library (see it is included above as -lgsl).
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Projects\Makefile.win" all
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"
gcc.exe main.o -o "Project2.exe" -L"C:/Dev-Cpp/lib"
main.o(.text+0x3a):main.c: undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status
make.exe: *** [Project2.exe] Error 1
Execution terminated
This appears in your compiler log:
windres.exe -i Projeto1_private.rc --input-format=rc -o Projeto1_private.res -O coff
I don't know what that is, but Clifford probably does.
See ya
Butch
You need to post all the text from the Compile Log window (not the "Compiler" window) for us to see what your problem is.
The almost certainty is that you have omitted to explicitly link the appropriate library.
Clifford
No, the library is correct.
This is a example program from: http://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html
But, It and the other functios doesn't work.
Code:
include <stdio.h>
include <gsl/gsl_sf_bessel.h>
int main()
{
}
Log:
Compilador: Default compiler
Building Makefile: "C:\Dev-Cpp\projetos\Makefile.win"
Executando make...
make.exe -f "C:\Dev-Cpp\projetos\Makefile.win" all
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/gsl"
windres.exe -i Projeto1_private.rc --input-format=rc -o Projeto1_private.res -O coff
gcc.exe main.o Projeto1_private.res -o "Projeto1.exe" -L"C:/Dev-Cpp/lib"
main.o(.text+0x3a):main.c: undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status
make.exe: *** [Projeto1.exe] Error 1
Execução terminada
I think you missed the point, no where in the compile log does it show the library being included. On the tool bar go to Project>>Project Options. When the Project Options dialog comes up go to the Parameters tab, in the linker column far right, have you explicitly added your library there? If not then do so.
Hi Everyone:
Stupid question of the day, but you didn't state that you did this.
Did you include the GSL library in your project? I don't mean the header file, I mean the library itself. I don't have the GSL installed on this computer so I can't tell you exactly what you need to include, but did you include the gsl.a library? You would have added it to the linker options and it would look something like: -lgsl ????
See Ya
Butch
There is a section in the thread titled "Please Read Before Posting a Question" on the compile log, including headers, and linking libraries that you may want to check out. It goes into some of the mechanics of the process.
As Clifford and Butch have pointed out, if you want to use a library, you MUST specifically link that library to your executable. You can do it either by the process that Clifford indicated, or the somewhat more old fashioned way (a personal favorite) that Butch laid out (familar to those who are used to doing things from the command line). It is not enough to have the library in the search path.
If you do a bit of searching on GSL here in the forum, you will probably stumble across some work I did several years ago.
Wayne
>> No, the library is correct.
That is not what I asked. Your log clearly shows that you have not linked the library at all. I don't mean installed teh library, or included teh header but linked the library.
In your log, this line:
gcc.exe main.o Projeto1_private.res -o "Projeto1.exe" -L"C:/Dev-Cpp/lib"
invokes the linker. You have not specified the library, or the library's location. That is how I know, and why the log is necessary. The link you posted even discusses "compiling and linking", and shows you what the command line should look like (albeit for a different platform and so slightly different to what is needed here).
First of all you need to determine where your libgsl.a file is. If it is not in C:/Dev-Cpp/lib (and I recommend not putting it there BTW), then you need to add the path in Project|Project options|Directories|Library Directories. Next in Project|Project options|Parameters|Linker, add -lgsl (that is -<lowercase-L>gsl not a <one> or anything else). You may need to add other libraries such as -lgslblas for example. You do not need to add -lm (the standard math library) as suggested in teh documentation you linked to, since this is a default library. and will be linked in any case.
>> either by the process that Clifford indicated
That was BiT actually, not me.
Clifford