我正在尝试编译示例 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
来解决此问题。我仍然收到上述错误。我该如何解决这个问题?
谢谢!
-洛汗。
最佳答案
尝试使用 -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?
这意味着还有其他需要解析的符号不在您链接的库中。请注意,您需要更改这两个库(命令行上有两个库)。也可能它们的顺序是错误的。
关于使用gcc时找不到库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13483669/