使用 mingw g++ 编译器在控制台编程环境中使用 boost

Using boost in console programming environment with mingw g++ compiler

我按照此处的说明安装了 boost:https://phylogeny.uconn.edu/tutorial-v2/part-1-ide-project-v2/setting-up-the-boost-c-library-v2/#

在 Visual Studio 中有效,但在 windows cmd 中使用 mingw g++ 编译时无效。

编辑是vim。

源代码如下:

#include <boost/algorithm/string.hpp>
...

像这样编译:

> g++ -o test test.cpp
test.cpp:7:10: fatal error: boost/algorithm/string.hpp: No such file or directory
 #include <boost/algorithm/string.hpp>

如何使我的 mingw g++ 可用于增强?

您使用了页面中的配置:

import option ; 
using msvc ; 
option.set keep-going : false ; 
libraries = --with-program_options --with-regex --with-filesystem --with-system ;

using msvc 应该可以告诉你一些事情。它使用 MSVC 工具链。因为它们不可互操作(不同的 C++ 运行时库,对于初学者来说,可能有不同的 ABI),你不能 link 这些库。

Header 仅

如果像您显示的代码一样,您只需要 headers,那没问题,只需将包含路径添加到您的编译器标志中,教程还告诉您:

所以要么直接输入命令行选项:

g++ -I C:\boost_1_65_0

或者添加到构建脚本中的变量,例如 Makefile:

CPPFLAGS+=-I C:\boost_1_65_0

或CMake:

INCLUDE_DIRECTORIES(C:\boost_1_65_0)

有链接

要使用pre-built共享库,您需要为mingw构建不同的版本。参见例如这些步骤:https://gist.github.com/zrsmithson/0b72e0cb58d0cb946fc48b5c88511da8

我从上周开始安装 (context),并且运行良好。 (我也最终选择 no-IDE 和 Vim,虽然 VsCode 也不错)

Check that it is using the mingw toolchain (e.g. mgw81) which also means that mgw81 shoud be part of the library filenames. Following just that tutorial already gives you this, but your previously existing configs might interfere if you're not careful.