C++ 在 eclipse cdt 中链接静态库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4952403/
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:00:14  来源:igfitidea点击:

link static lib in eclipse cdt

c++eclipsestatic-libraries

提问by JonnyCplusplus

I am sorry! I have googled this a lot and cannot find an answer! It's dumb I know.

对不起!我在谷歌上搜索了很多,但找不到答案!我知道这很愚蠢。

I cannot link in static libraries(*.a) in eclipse cdt. I listed them all in Project->Settings-> GCC C++ linker -> Libraries. I used the absolute path to make sure I had the lib correct... and i get:

我无法在 eclipse cdt 中链接静态库 (*.a)。我在项目->设置-> GCC C++ 链接器-> 库中列出了它们。我使用绝对路径来确保我的库正确......我得到:

cannot find -l/usr/local/lib/libboost_date_time.a

找不到 -l/usr/local/lib/libboost_date_time.a

I am sure it's stupid whatever I am doing wrong :(

我敢肯定,无论我做错了什么,这都是愚蠢的:(

Edit -- and i should mention i am linking the libraries at run time...

编辑 - 我应该提到我在运行时链接库......

采纳答案by Ralf

I remember having a similar issue way back when I was compiling our code under linux (coming from a windows background) and if I recall correctly specifying the absolute path to the static lib also didn't work.

我记得我在 linux 下编译代码时遇到了类似的问题(来自 Windows 背景),如果我记得正确指定静态库的绝对路径也不起作用。

Are you aware that to link to "libboost_date_time.a", you need to specify "boost_date_time" without the "lib" and the ".a"? In my case that solved the problem. /usr/local/lib should be on your path in any case AFAIR.

您是否知道要链接到“libboost_date_time.a”,您需要指定“boost_date_time”而不带“lib”和“.a”?在我的情况下,解决了这个问题。/usr/local/lib 无论如何都应该在您的路径上。

回答by jww

Static libraries or archives are just a collection of object files.

静态库或档案只是目标文件的集合。

Add the archive as Other Objectsunder C/C++ Build -> Settings -> C++ Linker -> Miscellaneous:

C/C++ Build -> Settings -> C++ Linker -> Miscellaneous下将存档添加为其他对象

enter image description here

在此处输入图片说明

Some folks cry bloody murder over specifying a full pathname. I find it works in practice (unlike theory at times), and its no worse than breaking the pathand filename, and then specifying them with -Land -l. And did I mention it actually works in practice...

有些人会因为指定一个完整的路径名而痛哭流涕。我发现它在实践中有效(有时与理论不同),并且不比破坏pathfilename,然后用-Land指定它们更糟糕-l。我有没有提到它实际上在实践中有效......

回答by Mauricio Quintana

I had the similar problem when adding the libs in the C/C++ General->Paths & Symbolsconfiguration screen.

C/C++ General->Paths & Symbols配置屏幕中添加库时,我遇到了类似的问题。

Instead on the C/C++ Build -> settingsscreen under GCC C++ Linker / LibrariesI added the library name without lib and .ain Libraries (-l) and adding the path in Libraries search path (-L). This solved my problem

相反,在C/C++ Build -> settings屏幕下,GCC C++ Linker / Libraries我添加了没有 lib 的库名称和.a库 (-l) 并在库搜索路径中添加了路径(-L)。这解决了我的问题