GSL

> Hello, 
>   I have installed the GSL libs via setup and am trying to get the following 
> example program to work: 

> #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; 
>      } 

> The compiler/linker is able to locate the header ok, but the error message I 
> get on the line that calls the function is: 

> undefined reference to `_gsl_sf_bessel_J0' 

> Somehow the function name got mangled with an added underscore, and of 
> course, it doesn't exist. 
>

It compiles and links fine for me using "gcc t.cpp -lgsl". Are you sure 
you are putting -lgsl in the right place on the command line (ie, at the 
end)? If you are, try compiling with "gcc -v -v t.cpp -lgsl", here is 
that output for me: 

$ gcc t.cpp -v -v -lgsl 
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs 
Configured with: 
/usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose 
--prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib 
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info 
--enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls 
--without-included-gettext --enable-version-specific-runtime-libs 
--without-x --enable-libgcj --disable-java-awt --with-system-zlib 
--enable-interpreter --disable-libgcj-debug --enable-threads=posix 
--enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions 
--enable-hash-synchronization --enable-libstdcxx-debug 
Thread model: posix 
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/cc1plus.exe -quiet -v -v 
-D__CYGWIN32__ -D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter 
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/w32api -idirafter 
/usr/local/lib/../../include/w32api t.cpp -quiet -dumpbase t.cpp 
-mtune=pentiumpro -auxbase t -version -o 
/cygdrive/c/DOCUME~1/Lewis/LOCALS~1/Temp/cc1w4jdk.s 
ignoring nonexistent directory 
"/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/include" 
ignoring duplicate directory "/usr/local/lib/../../include/w32api" 
#include "..." search starts here: 
#include <...> search starts here: 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++ 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/i686-pc-cygwin 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward 
  /usr/local/include 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/include 
  /usr/include 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/w32api 
End of search list. 
GNU C++ version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) 
(i686-pc-cygwin) 
         compiled by GNU C version 3.4.4 (cygming special, gdc 0.12, 
using dmd 0.125). 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
t.cpp:10:7: warning: no newline at end of file 
  
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/as.exe 
-o /cygdrive/c/DOCUME~1/Lewis/LOCALS~1/Temp/ccGPvaYJ.o 
/cygdrive/c/DOCUME~1/Lewis/LOCALS~1/Temp/cc1w4jdk.s 
  /usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic 
--dll-search-prefix=cyg 
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../crt0.o -L/usr/local/lib 
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../.. 
/cygdrive/c/DOCUME~1/Lewis/LOCALS~1/Temp/ccGPvaYJ.o -lgsl -lgcc -lcygwin 
-luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc 


It also works fine with g++ for me. 

-Lewis 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值