在 Eclipse 中将 Boost 链接到我的 C++ 项目

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

Linking Boost to my C++ project in Eclipse

c++regexeclipseboostlinker

提问by MahlerFive

I'm trying to get the Boost library working in my C++ projects in Eclipse. I can successfully build when using header-only libraries in Boost such as the example simple program in the "Getting Started" guide using the lambda header.

我正在尝试让 Boost 库在 Eclipse 中的 C++ 项目中工作。在 Boost 中使用仅标头库时,我可以成功构建,例如“入门”指南中使用 lambda 标头的示例简单程序。

I cannot get my project to successfully link to the regex Boost library as shown later in the guide. Under my project properties -> c/c++ build -> settings -> tool settings tab -> libraries, I have added "libboost_regex" to the Libraries box, and "C:\Program Files\boost\boost_1_42_0\bin.v2\libs" to the Library search path box since this is where all the .lib files are. I've even tried adding "libboost_regex-mgw34-mt-d-1_42.lib" to the libraries box instead of "libboost_regex" since that is the exact file name, but this did not work either.

我无法让我的项目成功链接到 regex Boost 库,如指南后面所示。在我的项目属性-> c/c++ 构建-> 设置-> 工具设置选项卡-> 库下,我已将“libboost_regex”添加到“库”框中,以及“C:\Program Files\boost\boost_1_42_0\bin.v2\libs " 到库搜索路径框,因为这是所有 .lib 文件所在的位置。我什至尝试将“libboost_regex-mgw34-mt-d-1_42.lib”添加到库框中而不是“libboost_regex”,因为这是确切的文件名,但这也不起作用。

I keep getting an error that says "cannot find -llibboost_regex" when I try to build my project. Any ideas as to how I can fix this?

当我尝试构建我的项目时,我不断收到一条错误消息,提示“找不到 -llibboost_regex”。关于如何解决这个问题的任何想法?

Edit: on Windows XP, using mingw, and I have tried "boost_regex" as well..

编辑:在 Windows XP 上,使用 mingw,我也尝试过“boost_regex”。

回答by Alex Jasmin

I just went through the whole process of installing MinGW, compiling boost and installing Eclipse CDT and I'm able to compile simple programs using boost:regex. I'll write down all the steps. I hope that can be of help.

我刚刚完成了安装 MinGW、编译 boost 和安装 Eclipse CDT 的整个过程,我能够使用boost:regex. 我会写下所有的步骤。我希望这能有所帮助。

I've installed MinGW and MSYS in their default location.

我已经在它们的默认位置安装了 MinGW 和 MSYS。

Here are the step I took to build boost:

以下是我为构建 boost 所采取的步骤:

  • Download boost-jam-3.1.18-1-ntx86.zip from http://sourceforge.net/projects/boost/files/boost-jam
  • Put bjam.exe somewhere in your PATH
  • Unpack boost in C:\mingw\boost_1_42_0
  • Open an msys terminal window and cd /c/mingw/boost_1_42_0
  • In the boost directory run bjam --build-dir=build toolset=gcc stage
  • http://sourceforge.net/projects/boost/files/boost-jam下载 boost-jam-3.1.18-1-ntx86.zip
  • 将 bjam.exe 放在 PATH 中的某个位置
  • 解压提升 C:\mingw\boost_1_42_0
  • 打开一个 msys 终端窗口并 cd /c/mingw/boost_1_42_0
  • 在 boost 目录中运行 bjam --build-dir=build toolset=gcc stage

To configure Eclipse:

配置 Eclipse:

  • Add CDT to Eclipse 3.5 from the update site
  • Create a new C++ project
  • Under the Projectmenu select properties
  • Make sure the configuration is Debug [Active]
  • In "C/C++ General" > "Paths and Symbols"

    • Under the Includestab select the GNU C++language and add C:\MinGW\boost_1_42_0
    • Under the Library Pathstab add C:\MinGW\boost_1_42_0\stage\lib
  • In "C/C++ Build" > "Settings"

    • Select MinGW C++ Linker> Libraries
    • Click on the add button for Libraries (-l)
    • Type libboost_regex-mgw34-mt-d(without the .lib)
  • 更新站点将 CDT 添加到 Eclipse 3.5
  • 创建一个新的 C++ 项目
  • 项目菜单下选择属性
  • 确保配置为Debug [Active]
  • 在“ C/C++ 通用”>“路径和符号”中

    • Includes选项卡下选择GNU C++语言并添加C:\MinGW\boost_1_42_0
    • 库路径选项卡下添加C:\MinGW\boost_1_42_0\stage\lib
  • 在“ C/C++ 构建”>“设置”中

    • 选择MinGW C++ 链接器>
    • 单击的添加按钮(-l)
    • 类型libboost_regex-mgw34-mt-d(不带 .lib)

You can then go through the same steps for the Releaseconfiguration but use libboost_regex-mgw34-mtinstead. Also make sure your source files include <boost/regex.hpp>

然后,您可以对Release配置执行相同的步骤,但请libboost_regex-mgw34-mt改为使用。还要确保您的源文件包括<boost/regex.hpp>

回答by erzam

To link to boost library in eclipse you need to set both the eclipse's project library path(the one with the -L) and the name of the library(the one with the -l).

要在 eclipse 中链接到 boost 库,您需要设置 eclipse 的项目库路径(带有 -L 的路径)和库的名称(带有 -l 的路径)。

The prefix 'lib' and the extension of the library's name must be removed:- eg: libboost_regex.a should be specified as boost_regex.

必须删除前缀“lib”和库名称的扩展名:- 例如:libboost_regex.a 应指定为 boost_regex。

回答by zdan

I believe your lib path is pointing to the wrong place. The libs will be installed to:

我相信你的 lib 路径指向错误的地方。这些库将安装到:

boost_install_dir\boost_1_42\lib

boost_install_dir\boost_1_42\lib

I think the default boost_install_dir is "C:\Program Files\Boost" (not sure because I don't use the default install directory).

我认为默认的 boost_install_dir 是“C:\Program Files\Boost”(不确定,因为我不使用默认安装目录)。