简体   繁体   English

在 Windows 上使用 Boost 和 Cygwin

[英]Using Boost with Cygwin on Windows

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.我正在使用 cygwin 在 winxp 机器上使用 g++ 进行编程。 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.我需要修改二阶 Bessel 函数,所以我下载了最新版本的 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.我在命令行中尝试了所有可能的 -L、-l、-I 选项组合以包含目录,但无济于事。 Also tried to add the folder in the PATH line of my windows system.还尝试在我的 windows 系统的 PATH 行中添加文件夹。

How do I link to the /boost directory and ALSO to all subdirectories?如何链接到 /boost 目录和所有子目录? The header file 'lambda.hpp' is calling other header files in subdirectories. header 文件 'lambda.hpp' 正在调用子目录中的其他 header 文件。

You're probably not that familiar with C++ yet?您可能还不太熟悉 C++ 吗? It seems you are confusing terms.看来您混淆了术语。

C++ programs are built in two steps: compiling and linking. C++ 程序的构建分为两个步骤:编译和链接。 In the first step, each source file (typically called.cpp) is handled individually.在第一步中,每个源文件(通常称为.cpp)都是单独处理的。 Each.cpp file usually uses multiple headers, so the compiler first inserts those - literally.每个.cpp 文件通常使用多个头文件,因此编译器首先插入这些头文件 - 字面意思。 That's why it's called #include.这就是为什么它被称为#include。

In the second step, the linker takes all the compiled.cpp files together and builds your final program.在第二步中,linker 将所有已编译的.cpp 文件放在一起并构建您的最终程序。 Some of those compiled.cpp's might have been bundled together before, in which the bundle is called a library.其中一些已编译的.cpp 可能以前捆绑在一起,其中捆绑称为库。

Boost is a collection of headers and.cpp files. Boost 是头文件和.cpp 文件的集合。 So, both compiler and linker might need to find the Boost directories.因此,编译器和 linker 可能都需要找到 Boost 目录。 From your error message, it's clear that the compiler step is the problem.从您的错误消息中,很明显编译器步骤是问题所在。 The linker does not need headers anymore. linker 不再需要标头。

The compiler will see the #include <boost/lambda/lambda.hpp> instuction.编译器将看到#include <boost/lambda/lambda.hpp>指令。 That means it needs to know where that first-level boost directory is found.这意味着它需要知道在哪里可以找到第一级boost目录。 I would guess at this point that the path would be /lib/boost_ 1_ 38_0/include (there's always the find / -name lambda.hpp shotgun appraoch)我猜此时路径将是/lib/boost_ 1_ 38_0/include (总是有find / -name lambda.hpp shotgun appraoch)

If you are not utterly wedded to cygwin, you should take a look at http://nuwen.net/mingw.html which 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 ZF6F87C9FDCF8B3C3F07F93F1ZEE871 为你安装所有的库。

Edit: I should make it clear you can use this MinGW installation in addition to Cygwin, not as a replacement.编辑:我应该明确指出,除了 Cygwin 之外,您还可以使用这个 MinGW 安装,而不是作为替代品。 Just make sure the MinGW bin directory appears in your PATH before the Cygwin one.只需确保 MinGW bin 目录出现在您的 PATH 中 Cygwin 之前。

I think you need -I /lib/boost_1_38_0 - although that's a pretty unusual place to put it.我认为您需要-I /lib/boost_1_38_0 - 尽管这是一个非常不寻常的地方。 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?你必须让我们知道你是如何安装它的,你是把它解压到你说的位置,还是你运行了makefile? I assume that since you gave a windows path you didn't install it within cygwin - which you probably should do.我假设由于您提供了 windows 路径,因此您没有在 cygwin 中安装它 - 您可能应该这样做。 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. 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 的回答

Thank you all for the information, it's a nice introduction to the use of libraries with cygwin.谢谢大家的信息,这是一个很好的介绍使用 cygwin 库。 Daniel was right.丹尼尔是对的。 While any variation gives an error, the following line (using caps i) does the trick:虽然任何变化都会产生错误,但以下行(使用 caps 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。

ps 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. ps 我只是在该文件夹中下载并解压缩了 boost,但由于我只使用 header 文件,我可能不需要使用 cygwin 编译。 [The boost version included with cygwin was 1.33, which does not seem to have Bessel functions.] 【cygwin自带的boost版本是1.33,好像没有贝塞尔函数。】

This is on win7 cygwin64 g++ 5.4, and boost-1.64.7z on 2017-7.这是在 win7 cygwin64 g++ 5.4 和 2017-7 的 boost-1.64.7z 上。 Google doesn't show any useful result for getting started for boost on windows (is boost out of fashion?).谷歌没有显示任何有用的结果来开始提升 windows(提升过时了吗?)。

By experimenting, I managed to compile and run a boost graph sample program as follows:通过实验,我设法编译并运行了一个 boost graph 示例程序,如下所示:

  :: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM