boost asio示例编译错误 [英] boost asio example compilation error

查看:141
本文介绍了boost asio示例编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常了解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]中):

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

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

是的,我检查了权限,并且在编译时我遇到了一个新问题,而a太困惑了

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

然后我尝试使用此命令进行编译: 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-保持 而我有这个错误:

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

然后我尝试使用此命令 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

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

这有错误

/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++ -Wall -g -I/usr/include/boost

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

,其中-Wall询问所有警告,-g询问调试信息,并且-I/usr/include/boost将include目录添加到include路径.

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

您确实应该使用 GNU Make 这样的构建器.现在该学习如何编写Makefile了.然后,您应该在Makefile中添加类似

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

如果request.hpp是当前目录中的您自己的文件(不是某个系统库中的文件),则应在其中包含双引号字符,例如

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"

,请勿使用<request.hpp>,否则将-I.添加到您的编译命令中.

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

请确保使用pwdls命令在正确的目录中运行编译. ls命令应同时显示request.hppconnection.cpp.使用 cd 命令(调用 bash脚本

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

您可能希望将-v(显示为编译而启动的实际程序)和-H(显示所包含的文件)传递给编译器.

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

请记住,g++编译器的参数顺序很重要;源文件应该放在目标文件和库之前,并且所有文件都应该从高级到低级(例如系统库).阅读有关调用GCC 的章节.您可能需要一些-L选项.

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.

顺便说一句,有几个HTTP服务器库可用,例如 libonion (同时支持HTTP和HTTPS).

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

这篇关于boost asio示例编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆