在Arch Linux中使用c++Boost正则表达式库

Using the c++ Boost regex libraries in Arch Linux

本文关键字:c++Boost 正则表达式 Arch Linux      更新时间:2023-10-16

我在构建一个简单的c++程序以测试boost库中的regex时遇到了问题。我遇到的问题发生在链接阶段,我不知道如何独自修复错误。

在使用正则表达式的.cpp程序中,我使用了以下include行。

#include <boost/regex.hpp>

我不知道该用什么命令来用g++构建程序。我尝试使用以下命令行(及其变体)来构建程序。

g++ -I/usr/include/regex -L/usr/lib -llibboost_regex main.cpp -o regex_test

其他可能相关的信息:

Operating system: Arch linux
g++ version: 4.6.2 20120120 (prerelease)

如有任何帮助,我们将不胜感激。

假设您已经安装了带有boostboost-libs包的Boost,

  1. 标头<boost/regex.hpp>应存在于/usr/include/boost/regex.hpp中。您不需要使用任何-I标志,因为默认情况下应该包括/usr/include
  2. 您也不需要-L标志,因为链接时默认情况下也应包括/usr/lib
  3. 当使用-l标志与库libfoo.so链接时,应删除前导的"lib"部分

因此,命令行应该是:

g++ main.cpp -o regex_test -lboost_regex