3

I'm getting errors when trying to run the HTTP server example that comes with the source of the boost library, under the path: boost_1_59_0/libs/asio/example/cpp11/http/server/.

I already ran this following commands in the boost_1_59_0 directory:

  • $ ./bootstrap.sh
  • $ sudo ./bjam install
  • $ sudo ./b2 install

After installing all targets, i tried to compile the main.cpp and the server.cpp with this command: g++ -std=c++0x -o main main.cpp -I "/home/user/Desktop/boost_1_59_0" -L "/home/user/Desktop/boost_1_59_0/libs/" -lboost_system. Any suggestion on how to compile this server example?

I linked all files from the boost_1_59_0/libs/asio/example/cpp11/http/server/ folder after the main.cpp, as @Richard Hodges suggested. It still didn't work, i got errors concerning lpthread, so i added it to the compiling options. The program compiled but it failed the execution, returning an error saying that it didn't find the library libboost_system.so.1.59.0. I tried linking the folders with -L /path/to/library but it didn't work.

Solution:

My compilation command:

g++ -std=gnu++0x -o main main.cpp server.cpp connection.cpp connection_manager.cpp reply.cpp mime_types.cpp request_handler.cpp request_parser.cpp -I "/home/user/Desktop/boost_1_59_0" -lboost_system -lpthread

I solved it with this commands:

  • $ LD_LIBRARY_PATH="/usr/local/lib/"
  • $ sudo ldconfig

And then I just ran the executable and it worked!

5
  • 1
    what command line did you use to compile the example? did you remember -lboost-system? what error output did you get? Commented Oct 22, 2015 at 13:57
  • I used this command: g++ -std=c++0x -o main main.cpp -I "/home/user/Desktop/boost_1_59_0" -L "/home/user/Desktop/boost_1_59_0/libs/" -lboost_system. I had an error about undefined reference to http::server::server::run()` Commented Oct 22, 2015 at 15:22
  • you need to mention all the other .cpp files on the command line. they go just after main.cpp Commented Oct 22, 2015 at 16:36
  • Thanks for the help Richard! Commented Oct 22, 2015 at 17:37
  • See also stackoverflow.com/questions/22314951/… Commented Oct 22, 2015 at 19:13

1 Answer 1

2

Here's a simple makefile I just concocted that works:

all:server

CPPFLAGS+=-std=c++11 -Wall -pedantic
CPPFLAGS+=-g -O2

CPPFLAGS+=-pthread
LDFLAGS+=-lboost_system

%.o:%.cpp
    $(CXX) $(CPPFLAGS) $^ -c -o $@

server:$(patsubst %.cpp,%.o,$(wildcard *.cpp))
    $(CXX) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

It runs make:

g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.cpp -c -o connection.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection_manager.cpp -c -o connection_manager.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread main.cpp -c -o main.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread mime_types.cpp -c -o mime_types.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread reply.cpp -c -o reply.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_handler.cpp -c -o request_handler.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_parser.cpp -c -o request_parser.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread server.cpp -c -o server.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.o connection_manager.o main.o mime_types.o reply.o request_handler.o request_parser.o server.o -o server -lboost_system

And the test program runs:

$ ./server 0.0.0.0 9889 . & 
$ GET http://localhost:9889/main.cpp > main.cpp.0

Check the files

$ md5sum main.cpp*
be5dc1c26b5942101a7895de6baedcee  main.cpp
be5dc1c26b5942101a7895de6baedcee  main.cpp.0

Don't forget to kill the server when you're done

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.