简体   繁体   English

/usr/bin/ld: 找不到

[英]/usr/bin/ld: cannot find

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:我创建了一个.so文件并将其放在位置/opt/lib中,然后当我尝试使用以下命令编译我的主程序时,现在将此路径添加到LD_LIBRARY_PATH

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我使用代码块 IDE 创建了共享库

-L/opt/lib添加到编译器参数中,这会使编译器和链接器在该文件夹中搜索libcalc.so的路径。

When you make the call to gcc it should say当你打电话给 gcc 它应该说

g++ -Wall -I/home/alwin/Development/Calculator/ -L/opt/lib main.cpp -lcalc -o calculator

not -libcalc.so 

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".然后图书馆变成“本地的”。

cd /compile/directory

ln -s  /path/to/libcalc.so libcalc.so

@Alwin Doss You should provide the -L option before -l. @Alwin Doss 您应该在 -l 之前提供 -L 选项。 You would have done the other way round probably.你可能会反过来做。 Try this :)尝试这个 :)

您需要添加-L/opt/lib来告诉ld在那里查找共享对象。

export LDFLAGS=-L/path to lib/ 这将解决错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM