C++ /usr/bin/ld: 找不到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5329638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:55:32  来源:igfitidea点击:

/usr/bin/ld: cannot find

c++linkershared-libraries

提问by Alwin Doss

I created a .sofile and put it in the location /opt/liband added this path to LD_LIBRARY_PATHnow 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 创建了共享库

回答by Dr. Snoopy

Add -L/opt/libto your compiler parameters, this makes the compiler and linker search that path for libcalc.soin that folder.

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

回答by otter

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

回答by geekosaur

You need to add -L/opt/libto tell ldto look there for shared objects.

您需要添加-L/opt/libto tellld在那里查找共享对象。

回答by Sunil

@Alwin Doss You should provide the -L option before -l. You would have done the other way round probably. Try this :)

@Alwin Doss 您应该在 -l 之前提供 -L 选项。你可能会反过来做。尝试这个 :)