【发布时间】: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) 确保它从 当前工作目录 而不是包含源的任何目录开始.