静态库链接不上,是怎么回事呢?

在Linux下 编译一个NCL 的C程序需要链接libnetcdf.a的一个静态库,它放在/usr/local/lib下,
编译时使用命令nhlcc -o test test.c -l/usr/local/lib/libnetcdf.a (NCL 自带命令)

即gcc -DSYSV -D_POSIX_SOURCE -D_XOPEN_SOURCE -DByteSwapped -D__UNIXOS2__ -DNeedFuncProto -ansi -fPIC -O0 -o cn14c cn14c.c -l/usr/local/lib/libnetcdf.a -L/usr/local/lib -I/usr/local/include -lhlu -lncarg -lncarg_gks -lncarg_c -lX11 -lXext -lgfortran -lm

但是报错
/usr/bin/ld: cannot find -l/usr/local/lib/libnetcdf.a
我查看了/ect/ld.so.conf.d/lic.conf文件中默认路径为/usr/local/lib 没有错啊,请问为什么还链不进去呢?
求高手指点!

作者: yan2865   发布时间: 2011-01-07

gcc -L

作者: lostyue   发布时间: 2011-01-07

gcc -L 库的路径

作者: lostyue   发布时间: 2011-01-07

-L/usr/local/lib -lnetcdf
试一下

作者: yifanernei   发布时间: 2011-01-07

-L/usr/local/lib 也不行,报错 
/tmp/ccU3mxIK.o: In function `main':
cn14c.c:(.text+0x892): undefined reference to `ncopen'
cn14c.c:(.text+0x8b2): undefined reference to `ncdimid'
cn14c.c:(.text+0x8d2): undefined reference to `ncdimid'
cn14c.c:(.text+0x906): undefined reference to `ncdiminq'
cn14c.c:(.text+0x933): undefined reference to `ncdiminq'
cn14c.c:(.text+0x94c): undefined reference to `ncvarid'
cn14c.c:(.text+0x9a7): undefined reference to `ncvarget'
cn14c.c:(.text+0x9c0): undefined reference to `ncvarid'
cn14c.c:(.text+0xa10): undefined reference to `ncvarget'
cn14c.c:(.text+0xa29): undefined reference to `ncvarid'
cn14c.c:(.text+0xa49): undefined reference to `ncvarid'
cn14c.c:(.text+0xac0): undefined reference to `ncvarget'
cn14c.c:(.text+0xafb): undefined reference to `ncvarget'
cn14c.c:(.text+0xb0a): undefined reference to `ncclose'
collect2: ld returned 1 exit status
库还是没有链进去的。

作者: yan2865   发布时间: 2011-01-07

把-L/usr/local/lib -lnetcdf放在链接库的最后面

还有使用nm看一下netcdf里面有ncopen之类的符号么,防止库有问题

作者: xunxun1982   发布时间: 2011-01-07