【问题标题】:Error compiling C++ source utilizing the Boost.Math library使用 Boost.Math 库编译 C++ 源代码时出错
【发布时间】:2023-03-06 20:50:01
【问题描述】:

我正在尝试使用 G++ 编译器在一些 C++ 代码中使用 Boost Math 库中的几个函数,但我没有成功。这是在 macOS 上。

我从 here 下载并提取了 Boost tar.gz 并将其放入我的源文件夹中。

在我尝试过的 C++ 中

#include "boost_1_63_0/boost/math/distributions/chi_squared.hpp"

#include <boost_1_63_0/boost/math/distributions/chi_squared.hpp>.

引用版本部分有效,但 chi_squared.hpp 文件包含 fwd.hpp 使用括号 (#include <...>) 表示法,这会破坏我的编译并出现错误 In file included from main.cpp:9: ./boost_1_63_0/boost/math/distributions/chi_squared.hpp:12:10: fatal error: 'boost/math/distributions/fwd.hpp' file not found #include <boost/math/distributions/fwd.hpp>

为了编译,我使用了各种各样的命令,但都没有成功:

g++ -L /boost_1_63_0/boost/math/distributions main.cpp

g++ -I"/boost_1_63_0/boost/math/" main.cpp

g++ -I "/boost_1_63_0/boost/math/" main.cpp

g++ main.cpp -lboost_math

我需要使用的正确 include 语句和 G++ 命令是什么?

【问题讨论】:

  • 试试-I/boost_1_63_0/。不要在源代码中提及 boost_1_63_0,只在编译标志中提及。
  • @n.'pronouns'm。所有的 boost 代码都在 boost_1_63_0 目录中,所以我只是列出了完整路径。将其分解为 #include "boost/math/distributions/chi_squared.hpp"g++ -I/boost_1_63_0/ main.cpp 配对产生 fatal error: boost/math/distributions/chi_squared.hpp' file not found
  • chi_squared.hpp 的完整路径是什么?
  • @n.'pronouns'm。从包含我的 CPP 源的目录中,路径是 boost_1_63_0/boost/math/distributions/chi_squared.hpp。当我使用引用包含符号的完整路径时,G++ 似乎能够找到 chi_squared.hpp 就好了。问题是chi_squared.hpp 包含其他带有括号符号的文件,而这些包含似乎是问题所在。
  • 完整或绝对路径从文件系统的根目录开始,而不是从其中的任何随机目录开始。大多数人在命令行中使用绝对路径。如果您更喜欢使用相对路径,那么您必须 (1) 删除前导 / 并 (2) 确保它从 当前工作目录 而不是包含源的任何目录开始.

标签: c++ macos boost g++


【解决方案1】:

解决方法

#include "/Users/[me]/[project_dir]/boost_1_63_0/boost/math/distributions/chi_squared.hpp"

g++ -I/Users/[me]/[project_dir]/boost_1_63_0/ main.cpp

【讨论】:

    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 2023-03-09
    • 1970-01-01
    • 2013-02-03
    • 2023-03-08
    • 2013-11-20
    相关资源
    最近更新 更多