/usr/bin/ld: 找不到
我创建了一个 .so
文件并将其放在 /opt/lib
位置,并将此路径添加到 LD_LIBRARY_PATH
现在,当我尝试使用以下命令编译我的主程序:
g++ -Wall -I/home/alwin/Development/Calculator/ main.cpp -lcalc -o calculator
我收到以下错误:
/usr/bin/ld: cannot find -lcalc
collect2: ld returned 1 exit status
有人可以帮我解决这个问题吗? 我使用代码块 IDE 创建了共享库
I created a .so
file and put it in the location /opt/lib
and added this path to LD_LIBRARY_PATH
now after this when I try to compile my main program with the following command:
g++ -Wall -I/home/alwin/Development/Calculator/ main.cpp -lcalc -o calculator
I get the following error:
/usr/bin/ld: cannot find -lcalc
collect2: ld returned 1 exit status
Can someone help me with this.
I created the shared library using the code blocks IDE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
-L/opt/lib
添加到编译器参数中,这使得编译器和链接器在该文件夹中搜索libcalc.so
的路径。Add
-L/opt/lib
to your compiler parameters, this makes the compiler and linker search that path forlibcalc.so
in that folder.@阿尔文·多斯
您应该在 -l 之前提供 -L 选项。你可能会采取相反的做法。试试这个:)
@Alwin Doss
You should provide the -L option before -l. You would have done the other way round probably. Try this :)
当您调用 gcc 时,它应该说
我对自动生成的品牌也有类似的问题。
您可以创建从编译目录到库目录的软链接。
那么图书馆就变得“本地”了。
When you make the call to gcc it should say
I have a similar problem with auto-generated makes.
You can create a soft link from your compile directory to the library directory.
Then the library becomes "local".
您需要添加 -L/opt/lib 来告诉 ld 在那里查找共享对象。
You need to add
-L/opt/lib
to tellld
to look there for shared objects.导出LDFLAGS=-L/lib/的路径这将解决错误
export LDFLAGS=-L/path to lib/ this will solve the error