如何在 Eclipse C++ 项目中包含静态链接库?

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

How do I include a statically linked library in my Eclipse C++ project?

c++eclipsestatic-librarieseclipse-cdt

提问by Thomas Owens

I have an open-source library that's distributed in source form. After I run the Makefile, I end up with a .hfile and a .afile that I then want to include in a project that I'm working on. I'm familiar with how I can add these by editing a Makefile manually or by invoking the compiler from the command line, but I'm not sure how I can add these to my Eclipse C++ project, created using the CDT.

我有一个以源代码形式分发的开源库。运行 Makefile 后,我最终会得到一个.h文件和一个.a文件,然后我想将其包含在我正在处理的项目中。我熟悉如何通过手动编辑 Makefile 或通过从命令行调用编译器来添加这些,但我不确定如何将这些添加到使用CDT创建的 Eclipse C++ 项目中。

I'm currently using Eclipse Indigo. I found some instructions for older versions of Eclipse, but the menus aren't what are described. I poked around a bit, and didn't see anything familiar.

我目前正在使用 Eclipse Indigo。我找到了一些关于旧版本 Eclipse 的说明,但菜单不是所描述的。我四处看了看,没有看到任何熟悉的东西。

回答by

right click on the project name in the project explorer with the project being opened, select project properties. Then select C/C++ General -> Paths and Symbols -> includes -> GNU C++ and add the path to your header file. You should do the same for you library under : C/C++ General -> Paths and Symbols -> Libraries -> Add , and add your library file path.

在打开项目的项目资源管理器中右键单击项目名称,选择项目属性。然后选择 C/C++ General -> Paths and Symbols -> includes -> GNU C++ 并将路径添加到您的头文件中。您应该在以下位置为您的库执行相同的操作: C/C++ General -> Paths and Symbols -> Libraries -> Add ,并添加您的库文件路径。

回答by Beginner

How do I add an external library to my C++ project?

如何将外部库添加到我的 C++ 项目中?

Go to Your Project's Properties by right clicking on project's name and selecting properties. Click on "C/C++ Build". Under Settings->Tool Settings Tab, click on GCC C Linker / Libraries. Then add a library and a search path.

通过右键单击项目名称并选择属性,转到您的项目属性。单击“C/C++ 构建”。在设置->工具设置选项卡下,单击 GCC C 链接器/库。然后添加一个库和一个搜索路径。