1
votes

i am very very beginner in boost and trying to compile c++ program from this link: http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3 (httpserver3 example) and so i tried to compile this project by using this command(in linux [debian]):

g++ -o htserv.exe connection.cpp main.cpp mime_types.cpp request_handler.cpp request_parser.cpp server.cpp

or

g++ -Wall -g -I /usr/local/include/boost connection.cpp main.cpp mime_types.cpp request_handler.cpp request_parser.cpp server.cpp -o htserv

and then i see this error :

In file included from connection.cpp:11:0:
connection.hpp:20:23: fatal error: request.hpp: No such file or directory
compilation terminated.
In file included from server.hpp:19:0,
                 from main.cpp:16:
connection.hpp:20:23: fatal error: request.hpp: No such file or directory
compilation terminated.
request_handler.cpp:18:23: fatal error: request.hpp: No such file or directory
compilation terminated.
request_parser.cpp:12:23: fatal error: request.hpp: No such file or directory
compilation terminated.
In file included from server.hpp:19:0,
                 from server.cpp:11:
connection.hpp:20:23: fatal error: request.hpp: No such file or directory

yes you right i checked the permission and i have a new problem when i compile and a was so confused

/tmp/ccj4xp5E.o: In function `http::server3::connection::handle_read(boost::system::error_code const&, unsigned long)':
/home/avakh/Desktop/boost/httpserver3/connection.cpp:56: undefined reference to `http::server3::reply::to_buffers()'
/home/avakh/Desktop/boost/httpserver3/connection.cpp:60: undefined reference to `http::server3::reply::stock_reply(http::server3::reply::status_type)'
/home/avakh/Desktop/boost/httpserver3/connection.cpp:64: undefined reference to `http::server3::reply::to_buffers()'
/tmp/ccj4xp5E.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/tmp/ccj4xp5E.o: In function `boost::system::error_code::error_code()':
/usr/local/include/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
/tmp/ccj4xp5E.o: In function `boost::asio::error::get_system_category()':
/usr/local/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
/tmp/ccH8QGhE.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/tmp/cclaofcI.o: In function `http::server3::request_handler::handle_request(http::server3::request const&, http::server3::reply&)':
/home/avakh/Desktop/boost/httpserver3/request_handler.cpp:34: undefined reference to `http::server3::reply::stock_reply(http::server3::reply::status_type)'
/home/avakh/Desktop/boost/httpserver3/request_handler.cpp:42: undefined reference to `http::server3::reply::stock_reply(http::server3::reply::status_type)'
/home/avakh/Desktop/boost/httpserver3/request_handler.cpp:66: undefined reference to `http::server3::reply::stock_reply(http::server3::reply::status_type)'
/tmp/cclaofcI.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/tmp/ccJ7jCu1.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/tmp/ccJ7jCu1.o: In function `boost::asio::detail::posix_signal_blocker::posix_signal_blocker()':
/usr/local/include/boost/asio/detail/posix_signal_blocker.hpp:43: undefined reference to `pthread_sigmask'
/tmp/ccJ7jCu1.o: In function `boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()':
/usr/local/include/boost/asio/detail/posix_signal_blocker.hpp:50: undefined reference to `pthread_sigmask'
/tmp/ccJ7jCu1.o: In function `boost::asio::detail::posix_thread::~posix_thread()':
/usr/local/include/boost/asio/detail/impl/posix_thread.ipp:35: undefined reference to `pthread_detach'
/tmp/ccJ7jCu1.o: In function `boost::asio::detail::posix_thread::join()':
/usr/local/include/boost/asio/detail/impl/posix_thread.ipp:42: undefined reference to `pthread_join'
/tmp/ccJ7jCu1.o: In function `boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
/usr/local/include/boost/asio/detail/impl/posix_thread.ipp:50: undefined reference to `pthread_create'
/tmp/ccJ7jCu1.o: In function `boost::thread_exception::thread_exception(int, char const*)':
/usr/local/include/boost/thread/exceptions.hpp:51: undefined reference to `boost::system::system_category()'
/tmp/ccJ7jCu1.o: In function `boost::detail::thread_data_base::thread_data_base()':
/usr/local/include/boost/thread/pthread/thread_data.hpp:144: undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/ccJ7jCu1.o: In function `boost::thread::start_thread()':
/usr/local/include/boost/thread/detail/thread.hpp:180: undefined reference to `boost::thread::start_thread_noexcept()'
/tmp/ccJ7jCu1.o: In function `boost::thread::~thread()':
/usr/local/include/boost/thread/detail/thread.hpp:255: undefined reference to `boost::thread::detach()'
/tmp/ccJ7jCu1.o: In function `boost::thread::get_id() const':
/usr/local/include/boost/thread/detail/thread.hpp:730: undefined reference to `boost::thread::native_handle()'
/tmp/ccJ7jCu1.o: In function `boost::thread::join()':
/usr/local/include/boost/thread/detail/thread.hpp:756: undefined reference to `boost::thread::join_noexcept()'
/tmp/ccJ7jCu1.o: In function `boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data()':
/usr/local/include/boost/thread/detail/thread.hpp:91: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccJ7jCu1.o:(.rodata._ZTIN5boost6detail11thread_dataINS_3_bi6bind_tImNS_4_mfi3mf0ImNS_4asio10io_serviceEEENS2_5list1INS2_5valueIPS7_EEEEEEEE[_ZTIN5boost6detail11thread_dataINS_3_bi6bind_tImNS_4_mfi3mf0ImNS_4asio10io_serviceEEENS2_5list1INS2_5valueIPS7_EEEEEEEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: error: ld returned 1 exit status

then i tried to use this command for compile: gcc -I /usr/local/include/boost/ -lboost_thread -lboost-asio -lboost_noncopyable -lboost_bind -lboost_logic -lboost_tuple -lboost_array connection.cpp mime_types.cpp main.cpp reply.cpp request_handler.cpp server.cpp -o hserv and i had this error:

/usr/bin/ld: cannot find -lboost-asio
/usr/bin/ld: cannot find -lboost_noncopyable
/usr/bin/ld: cannot find -lboost_bind
/usr/bin/ld: cannot find -lboost_logic
/usr/bin/ld: cannot find -lboost_tuple
/usr/bin/ld: cannot find -lboost_array
collect2: error: ld returned 1 exit status

then i tried to use this command g++ -I /usr/local/include/boost/ connection.cpp mime_types.cpp main.cpp reply.cpp request_handler.cpp server.cpp -o hserv -lboost-asio -lboost_noncopyable -lboost_bind -lboost_logic -lboost_tuple -lboost_array

and this had th error

/usr/bin/ld: cannot find -lboost-asio
/usr/bin/ld: cannot find -lboost_noncopyable
/usr/bin/ld: cannot find -lboost_bind
/usr/bin/ld: cannot find -lboost_logic
/usr/bin/ld: cannot find -lboost_tuple
/usr/bin/ld: cannot find -lboost_array
collect2: error: ld returned 1 exit status
2
Show your compilation command.Basile Starynkevitch
BTW, Linux executable files often don't end with .exe conventionally....Basile Starynkevitch
Did you install a libboost-all-dev package under your Ubuntu or Debian system....Basile Starynkevitch
So, where is your request.hpp file? If you put it in the same directory as connection.cpp the example should work.juanchopanza
You got something wrong. If the compiler tells request.hpp: No such file or directory you should believe it. Do the ls -l request.hpp command in the same terminal you are running your g++ command.Basile Starynkevitch

2 Answers

2
votes

Your compilation command probably should start with g++ -Wall -g -I/usr/include/boost

where -Wall asks for all warnings, -g asks for debugging information, and -I/usr/include/boost adds an include directory to the include path.

And you really should use a builder like GNU Make. It is time to learn how to write a Makefile. Then you should add in your Makefile a line like

  CXXFLAGS= -Wall -g -I/usr/include/boost

If request.hpp is your own file in the current directory (not one from some system library), you should include it with double-quotes characters like

  #include "request.hpp"

and not use <request.hpp> or else add -I. to your compilation command.

Be sure with the pwd and ls commands that you are running the compilation in the right directory. The ls command should show you both request.hpp and connection.cpp. Use the cd command (which calls the chdir(2) syscall) if needed. Take time to read more about bash scripting

You may want to pass -v (which shows the real programs launched for compilations) and -H (which shows the included files) to your compiler.

Remember that order of arguments to the g++ compiler is important; source files should go before object files and libraries, and all should go from high-level to low-level (e.g. system libraries). Read the chapter about invoking GCC. You might need some -L options.

BTW, there are several HTTP server libraries available, e.g. libonion (which supports both HTTP and HTTPS).

0
votes

I met the same problem in compiling with Ogre. I copied all the boost file(.a and .so) under /usr/local/lib to /usr/lib, it works.