本机 Ubuntu 与 Docker Ubuntu 之间的 Boost 库行为差异
Boost library behavior discrepancy between native Ubuntu vs Docker Ubuntu
我发现 Boost 库在 x86 本机上的行为与 docker 在 x86 主机上的行为存在差异,我想问问这个问题,看看我是否在做某事,或者是否存在错误被举报。
代码结构为:
boostHttpClient
|-include
| |-httpClient.hpp
|-src
| |-httpClient.cpp
|-CMakeLists.txt
我在 httpClient.hpp 中询问的部分是:
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/http/fields.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/strand.hpp>
#include <iostream>
#include <string>
#ifndef HTTP_CLIENT_HPP
#define HTTP_CLIENT_HPP
class httpSession : public std::enable_shared_from_this<httpSession>
{
public:
explicit
httpSession(boost::asio::any_io_executor executor);
我在 httpClient.cpp 中询问的部分是:
#include <httpClient.hpp>
httpSession::httpSession(boost::asio::any_io_executor executor)
: Resolver(executor)
, Stream(executor)
{
Version = 11;
Host.resize(0);
Port.resize(0);
ContentType.resize(0);
Authorization.resize(0);
Error = false;
}
和CMakeLists.txt是:
cmake_minimum_required(VERSION 3.10)
project(boostHttpClient)
add_library(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/httpClient.cpp)
target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/
)
target_link_libraries(${PROJECT_NAME}
pthread
boost_system
boost_thread
)
我正在使用两个不同的系统编译这个项目。
第一个系统是安装在 x86 英特尔处理器上的 Ubuntu 20.04 操作系统。代码编译没有任何问题。
boostHttpClient$ mkdir build
boostHttpClient$ cd build/
boostHttpClient/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: boostHttpClient/build
boostHttpClient/build$ make
Scanning dependencies of target boostHttpClient
[ 50%] Building CXX object CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o
[100%] Linking CXX static library libboostHttpClient.a
[100%] Built target boostHttpClient
第二个系统是安装在 x86 intel 主机上的 docker Ubuntu 20.04 操作系统。编译时代码产生错误
boostHttpClient# mkdir build
boostHttpClient# cd build/
boostHttpClient/build# cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: boostHttpClient/build
boostHttpClient/build# make
Scanning dependencies of target boostHttpClient
[ 50%] Building CXX object CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o
In file included from boostHttpClient/src/httpClient.cpp:10:
boostHttpClient/include/httpClient.hpp:25:45: error: expected ')' before 'executor'
25 | httpSession(boost::asio::any_io_executor executor);
| ~ ^~~~~~~~~
| )
boostHttpClient/src/httpClient.cpp:12:25: error: expected constructor, destructor, or type conversion before '(' token
12 | httpSession::httpSession(boost::asio::any_io_executor executor)
| ^
make[2]: *** [CMakeFiles/boostHttpClient.dir/build.make:63: CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/boostHttpClient.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
我的问题是为什么这段代码不能在第二个系统下编译。
-谢谢
据我所知,explicit
-ness 与事物无关。
看起来只是boost的版本不同,asio::any_io_executor
并不总是存在的。您也许可以替换 tieh asio::executor
。如果您显示更多代码(和版本),我们可以说更多。
@sehe 说的对。
我安装 boost 的方式就是这里的问题。我首先像这样在 Dockerfile 中安装 boost:
RUN apt install -y libboost-dev
RUN apt install -y libboost-all-dev
然而,如果我需要使用所有 boost 函数和功能,我应该像这样在 Dockerfile 中安装 boost:
RUN cd /home && wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz \
&& tar xfz boost_1_79_0.tar.gz \
&& rm boost_1_79_0.tar.gz \
&& cd boost_1_79_0 \
&& ./bootstrap.sh --prefix=/usr/local --with-libraries=program_options \
&& ./b2 install \
&& cd /home \
&& rm -rf boost_1_79_0
我试过了,成功了。
我发现 Boost 库在 x86 本机上的行为与 docker 在 x86 主机上的行为存在差异,我想问问这个问题,看看我是否在做某事,或者是否存在错误被举报。 代码结构为:
boostHttpClient
|-include
| |-httpClient.hpp
|-src
| |-httpClient.cpp
|-CMakeLists.txt
我在 httpClient.hpp 中询问的部分是:
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/http/fields.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/strand.hpp>
#include <iostream>
#include <string>
#ifndef HTTP_CLIENT_HPP
#define HTTP_CLIENT_HPP
class httpSession : public std::enable_shared_from_this<httpSession>
{
public:
explicit
httpSession(boost::asio::any_io_executor executor);
我在 httpClient.cpp 中询问的部分是:
#include <httpClient.hpp>
httpSession::httpSession(boost::asio::any_io_executor executor)
: Resolver(executor)
, Stream(executor)
{
Version = 11;
Host.resize(0);
Port.resize(0);
ContentType.resize(0);
Authorization.resize(0);
Error = false;
}
和CMakeLists.txt是:
cmake_minimum_required(VERSION 3.10)
project(boostHttpClient)
add_library(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/httpClient.cpp)
target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/
)
target_link_libraries(${PROJECT_NAME}
pthread
boost_system
boost_thread
)
我正在使用两个不同的系统编译这个项目。 第一个系统是安装在 x86 英特尔处理器上的 Ubuntu 20.04 操作系统。代码编译没有任何问题。
boostHttpClient$ mkdir build
boostHttpClient$ cd build/
boostHttpClient/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: boostHttpClient/build
boostHttpClient/build$ make
Scanning dependencies of target boostHttpClient
[ 50%] Building CXX object CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o
[100%] Linking CXX static library libboostHttpClient.a
[100%] Built target boostHttpClient
第二个系统是安装在 x86 intel 主机上的 docker Ubuntu 20.04 操作系统。编译时代码产生错误
boostHttpClient# mkdir build
boostHttpClient# cd build/
boostHttpClient/build# cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: boostHttpClient/build
boostHttpClient/build# make
Scanning dependencies of target boostHttpClient
[ 50%] Building CXX object CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o
In file included from boostHttpClient/src/httpClient.cpp:10:
boostHttpClient/include/httpClient.hpp:25:45: error: expected ')' before 'executor'
25 | httpSession(boost::asio::any_io_executor executor);
| ~ ^~~~~~~~~
| )
boostHttpClient/src/httpClient.cpp:12:25: error: expected constructor, destructor, or type conversion before '(' token
12 | httpSession::httpSession(boost::asio::any_io_executor executor)
| ^
make[2]: *** [CMakeFiles/boostHttpClient.dir/build.make:63: CMakeFiles/boostHttpClient.dir/src/httpClient.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/boostHttpClient.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
我的问题是为什么这段代码不能在第二个系统下编译。
-谢谢
据我所知,explicit
-ness 与事物无关。
看起来只是boost的版本不同,asio::any_io_executor
并不总是存在的。您也许可以替换 tieh asio::executor
。如果您显示更多代码(和版本),我们可以说更多。
@sehe 说的对。 我安装 boost 的方式就是这里的问题。我首先像这样在 Dockerfile 中安装 boost:
RUN apt install -y libboost-dev
RUN apt install -y libboost-all-dev
然而,如果我需要使用所有 boost 函数和功能,我应该像这样在 Dockerfile 中安装 boost:
RUN cd /home && wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz \
&& tar xfz boost_1_79_0.tar.gz \
&& rm boost_1_79_0.tar.gz \
&& cd boost_1_79_0 \
&& ./bootstrap.sh --prefix=/usr/local --with-libraries=program_options \
&& ./b2 install \
&& cd /home \
&& rm -rf boost_1_79_0
我试过了,成功了。