c++ - Running HTTP server example from Boost Asio -


i'm getting errors when trying run http server example comes source of boost library, under path: boost_1_59_0/libs/asio/example/cpp11/http/server/.

i ran following commands in boost_1_59_0 directory:

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

after installing targets, tried compile main.cpp , server.cpp 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. suggestion on how compile server example?

i linked files boost_1_59_0/libs/asio/example/cpp11/http/server/ folder after main.cpp, @richard hodges suggested. still didn't work, got errors concerning lpthread, added compiling options. program compiled failed execution, returning error saying didn't find library libboost_system.so.1.59.0. tried linking folders -l /path/to/library 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 commands:

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

and ran executable , worked!

here's simple makefile concocted 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 test program runs:

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

check files

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

don't forget kill server when you're done


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -