Home > Blockchain >  Boost library behavior discrepancy between native Ubuntu vs Docker Ubuntu
Boost library behavior discrepancy between native Ubuntu vs Docker Ubuntu

Time:05-03

I found a discrepancy in the behavior of Boost library on x86 native vs docker on a x86 host and I would like to ask about it and see if I am doing something work or there is a bug to be reported. the structure of the code is:

boostHttpClient
|-include
|  |-httpClient.hpp
|-src
|  |-httpClient.cpp
|-CMakeLists.txt

the part I am asking about in httpClient.hpp is:

#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);

the part I am asking about in httpClient.cpp is:

#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;
}

and CMakeLists.txt is:

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
                      )

I am compiling this project using two different systems. Firs system is an Ubuntu 20.04 operating system installed on x86 intel processor. The code compiles without any problem.

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

Second system is a docker Ubuntu 20.04 operating system installed on x86 intel host. The code generated error during compilation

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

My question is why this code is not compiling under the second system.

-Thanks

CodePudding user response:

As far as I can see the explicit-ness has nothing to with things.

It looks like the versions of boost are just different, asio::any_io_executor didn't always exist. You might be able to replace tieh asio::executor. If you show more code (and versions) we can say more.

CodePudding user response:

@sehe is right. The way I installed boost was the issue here. I first was installing boost in the Dockerfile like this:

RUN apt install -y libboost-dev
RUN apt install -y libboost-all-dev 

Yet if I need to use all of boost functions and capabilities, I should install boost in the Dockerfile like this:

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

I tried it and it worked.

  • Related