使用gcc时找不到库错误

时间:2012-11-20 22:59:04

标签: c

我正在尝试编译一个示例C程序,并使用以下命令将其链接到一些静态库文件:

gcc -I /usr/local/include -L /usr/local/lib -l libsundials_cvode.a -l libsundials_nvecserial.a cvRoberts_dns.c -o cvRoberts_dns.o

(我确信上面的库文件和包含文件目录是正确的。)

我得到的错误是:

/usr/bin/ld: cannot find -llibsundials_cvode.a
collect2: ld returned 1 exit status

我有两个问题:

1)我正确使用-L和-l选项吗?

2)以上错误是b / c gcc正在寻找错误位置的库文件吗?我尝试通过我的终端$LD_LOAD_PATH/usr/local/bin设置为{{1}}来解决此问题。我仍然得到上述错误。我该如何解决这个问题?

谢谢!

-Rohan。

1 个答案:

答案 0 :(得分:4)

尝试使用-lsundials_cvode - 删除'lib'和'.a'部分

请注意,LD_LOAD_PATH用于在运行时定位动态库,而不是在编译期间定位。

编辑:

I just tried that. The change addresses the cannot find library error but 
now I am faced with many "undefined reference to" errors. Does this mean 
the linking of the library files has failed somehow? How do I correct this? 

这意味着需要解析的其他符号不在您链接的库中。请注意,您需要更改两个库(命令行中有两个库)。也许他们的顺序错了。