gpt4 book ai didi

c++ - 关于 C++/Boost 的真正基础 - 测试 boost

转载 作者:行者123 更新时间:2023-11-28 07:39:13 24 4
gpt4 key购买 nike

我想我已经正确安装了 boost,所以我正在尝试使用找到的测试“first.cpp”here :

#include<iostream>
#include<boost/any.hpp>

int main()
{
boost::any a(5);
a = 7.67;
std::cout<<boost::any_cast<double>(a)<<std::endl;
}

我得到以下信息:

Jason@ITHAKA-DB44CFE1 /home/jason
$ g++ -o first first.cpp
first.cpp:2:24: boost/any.hpp: No such file or directory
first.cpp: In function `int main()':
first.cpp:6: error: `boost' has not been declared
first.cpp:6: error: `any' undeclared (first use this function)
first.cpp:6: error: (Each undeclared identifier is reported only once for each
unction it appears in.)
first.cpp:6: error: expected `;' before "a"
first.cpp:7: error: `a' undeclared (first use this function)
first.cpp:8: error: `boost' has not been declared
first.cpp:8: error: `any_cast' undeclared (first use this function)
first.cpp:8: error: expected primary-expression before "double"
first.cpp:8: error: expected `;' before "double"
first.cpp:9:2: warning: no newline at end of file

Jason@ITHAKA-DB44CFE1 /home/jason
$

我的 boost 库在我的 ./home/Jason/中的位置

显然有些事情发生了。此外,所有 boost 库本身都使用这个“boost/...”,所以出于某种原因:

1 - 我在 Boost 上做错了什么2 - C++/gcc 没有“看到”我的 boost

任何输入?

最佳答案

您需要将 -I/home/Jason/include 传递给 gcc,可能还有一个 -L/home/Jason/lib也是,因为库没有安装在标准路径中。尝试:

 g++ -I/home/Jason/include -L/home/Jason/lib -o first first.cpp

此外,一旦编译,它将无法正常运行,因为库再次不在标准路径中。要运行它,您需要将 /home/Jason/lib 添加到环境变量 LD_LIBRARY_PATH

编辑:正如 Tony D 指出的,您可以将 CPLUS_INCLUDE_PATH 设置为 /home/Jason/include,这相当于我给您的编译器选项。

编辑

如果您只想测试您的安装,您可以运行 ~/bin/Boost.Test 脚本(假设您启用了 --with-libraries=test当你安装它时)。否则 hour home 中应该有一个 bin 目录(如果你用它作为前缀),如果里面有任何名为 Boost 的东西,尝试运行它(但是记得之前设置LD_LIBRARY_PATH)。

关于c++ - 关于 C++/Boost 的真正基础 - 测试 boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16159692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com