c++ - 使用boost的字节序转换

标签 c++ boost endianness

我遵循了所谓的manual of boost用于转换(交换)字节序。

尽管他们 code比他们的手册更具可读性,有人可以解释一下我应该如何修复以下代码吗?

hh.cpp

#include <iostream>
#include <boost/array.hpp>
#include <boost/endian/conversion.hpp>

int main () {

  std::cout << boost::endian::endian_reverse(5);

  return 0;
}

制作:

g++ hh.cpp -o hh -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 -lboost_system -lrt  -lboost_wave -larmadillo -lboost_thread

错误:

hh.cpp:3:39: fatal error: boost/endian/conversion.hpp: No such file or directory
 #include <boost/endian/conversion.hpp>
                                       ^
compilation terminated.

更新

其他的 boost header 都包含在内。只有 endian 有问题。

ls /usr/include/boost/*

http://pastebin.com/nCciracE


更新

$ cat /usr/include/boost/version.hpp

结果:

//  Boost version.hpp configuration header file  ------------------------------//

//  (C) Copyright John maddock 1999. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org/libs/config for documentation

#ifndef BOOST_VERSION_HPP
#define BOOST_VERSION_HPP

//
//  Caution, this is the only boost header that is guarenteed
//  to change with every boost release, including this header
//  will cause a recompile every time a new boost version is
//  released.
//
//  BOOST_VERSION % 100 is the patch level
//  BOOST_VERSION / 100 % 1000 is the minor version
//  BOOST_VERSION / 100000 is the major version

#define BOOST_VERSION 105400

//
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
//  but as a *string* in the form "x_y[_z]" where x is the major version
//  number, y is the minor version number, and z is the patch level if not 0.
//  This is used by <config/auto_link.hpp> to select which library version to link to.

#define BOOST_LIB_VERSION "1_54"

#endif

最佳答案

endian 库在 boost version 1.58 中引入. 您有 1.54,此版本中没有 endian 库。您应该将 boost 更新到 1.58+,或者不使用 endian 库。

关于c++ - 使用boost的字节序转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874532/

相关文章:

c++ - 从 ProcessSerialNumber 获取应用程序图标

c++ - 跟进: Boost serialized custom C++ object passed over ZeroMQ pull socket

c++ - boost condition_variable 销毁断言

c - Linux 上的 betoh16/32 和 letoh16/32 的名称是什么?

c++ - 有没有办法为 C 或 C++ 结构强制执行特定的字节顺序?

python - 转换已存在的二进制文件的字节序类型

C++ 32 位与 64 位 float 限制

c++ - 匿名结构会更改布局和填充吗?

c++ - 简单表单的惯用 QT 架构?

c++ - 如何让 libtorrent 看到 boost ?