我是 boost 的初学者,并试图从这个链接编译 c++ 程序:http: //www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3 (httpserver3例如),所以我尝试使用这个命令(在 linux [debian] 中)编译这个项目:
g++ -o htserv.exe connection.cpp main.cpp mime_types.cpp request_handler.cpp request_parser.cpp server.cpp
或者
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
然后我看到这个错误:
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
是的,你说得对,我检查了权限,当我编译时遇到了一个新问题,我很困惑
/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
然后我尝试使用此命令进行编译: 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 我有这个错误:
/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
然后我尝试使用这个命令 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
这有错误
/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