在 Windows 上将 Boost 与 Cygwin 结合使用

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

Using Boost with Cygwin on Windows

windowsboostcygwin

提问by MSalters

This shoud be a simple problem for users more advanced than I am. :-) How do I use the boost library with cygwin on windows?

对于比我更高级的用户来说,这应该是一个简单的问题。:-) 如何在 Windows 上使用带有 cygwin 的 boost 库?

I am programing with g++ using cygwin on a winxp machine. I need modified Bessel functions of the second order, so I downloaded the latest version of the boost library and installed it in 'c:\cygwin\lib\boost_ 1_ 38_0\' folder.

我在 winxp 机器上使用 cygwin 使用 g++ 进行编程。我需要修改二阶贝塞尔函数,所以我下载了最新版本的boost库并将其安装在'c:\cygwin\lib\boost_1_38_0\'文件夹中。

I am trying to run the "example.cpp" program from the "getting started" section of their website: http://www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html

我正在尝试从他们网站的“入门”部分运行“example.cpp”程序:http: //www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html

I am compiling from the directory where I created the example file using a simple Bash shell command line: 'g++ -Wall example.cpp'

我正在使用简单的 Bash shell 命令行从创建示例文件的目录进行编译:'g++ -Wall example.cpp'

I keep getting the message: "boost/lambda/lambda.hpp: no such file or directory"

我不断收到消息:“boost/lambda/lambda.hpp:没有这样的文件或目录”

I tried every possible combination of -L, -l, -I options in the command line to include the directory, to no avail. Also tried to add the folder in the PATH line of my windows system.

我在命令行中尝试了 -L、-l、-I 选项的所有可能组合以包含目录,但无济于事。还尝试在我的 Windows 系统的 PATH 行中添加文件夹。

How do I link to the /boost directory and ALSO to all subdirectories? The header file 'lambda.hpp' is calling other header files in subdirectories.

如何链接到 /boost 目录并链接到所有子目录?头文件“lambda.hpp”正在调用子目录中的其他头文件。

回答by MSalters

You're probably not that familiar with C++ yet? It seems you are confusing terms.

你可能还不太熟悉 C++?看来你混淆了术语。

C++ programs are built in two steps: compiling and linking. In the first step, each source file (typically called .cpp) is handled individually. Each .cpp file usually uses multiple headers, so the compiler first inserts those - literally. That's why it's called #include.

C++ 程序分两步构建:编译和链接。在第一步中,每个源文件(通常称为 .cpp)都是单独处理的。每个 .cpp 文件通常使用多个标头,因此编译器首先插入这些标头 - 从字面上看。这就是它被称为#include 的原因。

In the second step, the linker takes all the compiled .cpp files together and builds your final program. Some of those compiled .cpp's might have been bundled together before, in which the bundle is called a library.

在第二步中,链接器将所有已编译的 .cpp 文件放在一起并构建您的最终程序。一些编译的 .cpp 之前可能已经捆绑在一起,其中的捆绑包称为库。

Boost is a collection of headers and .cpp files. So, both compiler and linker might need to find the Boost directories. From your error message, it's clear that the compiler step is the problem. The linker does not need headers anymore.

Boost 是头文件和 .cpp 文件的集合。因此,编译器和链接器可能都需要找到 Boost 目录。从您的错误消息中,很明显编译器步骤是问题所在。链接器不再需要标头。

The compiler will see the #include <boost/lambda/lambda.hpp>instuction. That means it needs to know where that first-level boostdirectory is found. I would guess at this point that the path would be /lib/boost_ 1_ 38_0/include(there's always the find / -name lambda.hppshotgun appraoch)

编译器会看到#include <boost/lambda/lambda.hpp>指令。这意味着它需要知道第一级boost目录的位置。在这一点上,我猜路径会是/lib/boost_ 1_ 38_0/include(总是有find / -name lambda.hpp霰弹枪的方法)

回答by MSalters

If you are not utterly wedded to cygwin, you should take a look at http://nuwen.net/mingw.htmlwhich gives you a complete MinGW C++ installation with all the libraries (such as Boost) set up for you.

如果您不完全依赖于 cygwin,您应该查看http://nuwen.net/mingw.html,它为您提供了一个完整的 MinGW C++ 安装,其中包含为您设置的所有库(例如 Boost)。

Edit:I should make it clear you can use this MinGW installation in addition to Cygwin, not as a replacement. Just make sure the MinGW bin directory appears in your PATH before the Cygwin one.

编辑:我应该明确指出,除了 Cygwin 之外,您还可以使用此 MinGW 安装,而不是作为替代品。只需确保 MinGW bin 目录出现在 Cygwin 之前的 PATH 中。

回答by Daniel James

I think you need -I /lib/boost_1_38_0- although that's a pretty unusual place to put it. You'll have to let us know how you installed it, did you just unzip it in the location you said, or did you run the makefiles? I assume that since you gave a windows path you didn't install it within cygwin - which you probably should do. The instructions in the getting started guide for unix should help - although don't download a prebuilt bjam- it needs to be built with cygwin.

我认为你需要-I /lib/boost_1_38_0- 尽管这是一个非常不寻常的地方。您必须让我们知道您是如何安装它的,您是将它解压缩到您所说的位置,还是运行了 makefile?我假设由于您提供了 Windows 路径,因此您没有在 cygwin 中安装它 - 您可能应该这样做。unix 入门指南中的说明应该会有所帮助 - 尽管不要下载预构建的bjam- 它需要使用 cygwin 构建。

But if you're not very familiar with cygwin (or unix in general) I think you might find it easier to use a native windows tool - as in Neil Butterworth's answer.

但是,如果您不太熟悉 cygwin(或一般的 unix),我认为您可能会发现使用本机 Windows 工具更容易 - 正如Neil Butterworth 的回答

回答by Daniel James

Thank you all for the information, it's a nice introduction to the use of libraries with cygwin. Daniel was right. While any variation gives an error, the following line (using caps i) does the trick:

谢谢大家提供的信息,这是对 cygwin 库使用的很好的介绍。丹尼尔是对的。虽然任何变化都会产生错误,但以下行(使用大写 i)可以解决问题:

g++ -Wall -I /cygdrive/c/cygwin/lib/boost_1_38_0/ example.cpp -o example

g++ -Wall -I /cygdrive/c/cygwin/lib/boost_1_38_0/example.cpp -o 示例

I will also check MinGW in the next few days.

我也会在接下来的几天检查 MinGW。

p.s. I simply downloaded and unzipped boost in that folder, but since I am only using header files I probably won't need to compile with cygwin. [The boost version included with cygwin was 1.33, which does not seem to have Bessel functions.]

ps 我只是在那个文件夹中下载并解压了 boost,但由于我只使用头文件,我可能不需要用 cygwin 编译。[cygwin 附带的 boost 版本是 1.33,它似乎没有 Bessel 函数。]

回答by mosh

This is on win7 cygwin64 g++ 5.4, and boost-1.64.7z on 2017-7. Google doesn't show any useful result for getting started for boost on windows (is boost out of fashion?).

这是在 2017-7 上的 win7 cygwin64 g++ 5.4 和 boost-1.64.7z 上。谷歌没有显示任何有用的结果来开始在 Windows 上提升(提升是否过时了?)。

By experimenting, I managed to compile and run a boost graph sample program as follows:

通过试验,我设法编译并运行了一个 boost 图示例程序,如下所示:

  :: g++ 5.4 in c:\cygwin64
  :: 7z extract boost download in c:\tools\boost\boost164
  > set BOOST_ROOT=c:\tools\boost\boost164
  > setx BOOST_ROOT  c:\tools\boost\boost164 -m
  > cd %BOOST_ROOT%
  > bootstrap.sh gcc  (the bat files doesn't work)
  > b2.exe
     ...failed updating 58 targets...
    ...skipped 18 targets...

    ...updated 1123 targets... 

  :: Lots of example here (not ranked highly by google)
  > mklink /D eg %BOOST_ROOT%/libs/graph/example

  :: Compiled and run [maxflow code using boost library][1] 
  :: http://vision.csd.uwo.ca/code
  > unzip ; vi Makefile
     CPPFLAGS = -I %BOOST_ROOT%/ 
     LDFLAGS = -L%BOOST_ROOT%/stage/lib 
  > make
  > set PATH=%PATH%;%BOOST_ROOT%/stage/lib
  > maxflow.exe 
    Flow = 6