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
/usr/bin/ld: cannot find
提问by Alwin Doss
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 创建了共享库
回答by Dr. Snoopy
Add -L/opt/lib
to your compiler parameters, this makes the compiler and linker search that path for libcalc.so
in 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/lib
to tell ld
to look there for shared objects.
您需要添加-L/opt/lib
to 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 选项。你可能会反过来做。尝试这个 :)