使用 Boost.Math 库编译 C++ 源代码时出错

时间:2021-05-07 05:45:33

标签: c++ macos boost g++

我正在尝试使用 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

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

1 个答案:

答案 0 :(得分:0)

解决使用

#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

相关问题