'Make can't find boost header in docker container
I'm trying to build a simple client server connection in docker with boost sockets. When I compile the files on ubuntu without docker it works. But when I try running make through a ubuntu docker container with boost preinstalled I get the following error:
> [6/6] RUN make && make all:
#10 0.526 g++ -g -std=c++11 -Wall -pthread -lpthread -lboost_system -lboost_thread -o async_udp_echo_server async_udp_echo_server.cpp
#10 0.556 async_udp_echo_server.cpp:13:10: fatal error: boost/bind.hpp: No such file or directory
#10 0.556 #include <boost/bind.hpp>
#10 0.556 ^~~~~~~~~~~~~~~~
#10 0.556 compilation terminated.
#10 0.557 make: *** [async_udp_echo_server] Error 1
#10 0.557 Makefile:52: recipe for target 'async_udp_echo_server' failed
I've looked into the image and the boost files can be found in the right directory (usr/include/boost). The Makefile looks like this:
CPP = g++
CPPFLAGS = -g -std=c++11 -Wall -pthread -lpthread -lboost_system -lboost_thread
PROGRAMS = async_udp_echo_server \
blocking_udp_echo_client
all: $(PROGRAMS)
$(PROGRAMS): %: %.cpp $(LIBS)
$(CPP) $(CPPFLAGS) -o $@ $<
clean:
rm -f $(PROGRAMS)
And the Dockerfile for the server, the first container being build, looks like this:
FROM zouzias/boost:latest
COPY . /usr/include/app
WORKDIR /usr/include/app
RUN apt-get update
RUN apt-get install -y g++ cmake make build-essential
RUN make && make all
CMD ['./blocking_udp_echo_client', 'localhost', '8888']
As suggested in another thread I also tried RUN apt-get install libboost-all-dev before executing make, which resulted in a different error:
#10 0.474 g++ -g -std=c++11 -Wall -pthread -lpthread -lboost_thread -lboost_filesystem -lboost_system -o async_udp_echo_server async_udp_echo_server.cpp
#10 1.465 /tmp/cciDjHYm.o: In function `__static_initialization_and_destruction_0(int, int)':
#10 1.465 /usr/include/boost/system/error_code.hpp:206: undefined reference to `boost::system::generic_category()'
#10 1.465 /usr/include/boost/system/error_code.hpp:208: undefined reference to `boost::system::generic_category()'
#10 1.465 /usr/include/boost/system/error_code.hpp:210: undefined reference to `boost::system::system_category()'
#10 1.465 /tmp/cciDjHYm.o: In function `boost::system::error_code::error_code()':
#10 1.465 /usr/include/boost/system/error_code.hpp:439: undefined reference to `boost::system::system_category()'
#10 1.465 /tmp/cciDjHYm.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
#10 1.465 /usr/include/boost/system/error_code.hpp:656: undefined reference to `boost::system::generic_category()'
#10 1.465 /usr/include/boost/system/error_code.hpp:659: undefined reference to `boost::system::generic_category()'
#10 1.465 /tmp/cciDjHYm.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
#10 1.465 /usr/include/boost/system/error_code.hpp:686: undefined reference to `boost::system::generic_category()'
#10 1.465 /usr/include/boost/system/error_code.hpp:689: undefined reference to `boost::system::generic_category()'
#10 1.465 /usr/include/boost/system/error_code.hpp:701: undefined reference to `boost::system::generic_category()'
#10 1.465 /tmp/cciDjHYm.o: In function `boost::asio::error::get_system_category()':
#10 1.465 /usr/include/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
#10 1.465 collect2: error: ld returned 1 exit status
#10 1.466 Makefile:52: recipe for target 'async_udp_echo_server' failed
#10 1.466 make: *** [async_udp_echo_server] Error 1
As you can see I already tried switching around the order of the library files and adding lboost_filesystem as I've read this error might be due to an incorrect order. The problem still persists though.
Is there somewhere I forgot to link libraries or what else can I do to troubleshoot this problem? I appreciate any advise.
Solution 1:[1]
I fixed the second error message by adding -DBOOST_ERROR_CODE_HEADER_ONLY to the CPPFLAGS in the Makefile, then you can just remove -lboost_system. Now everything works as it should.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
