(转)LINUX 网络编程之Daemon设计

(原)ubuntu 9.10 安装 asio库

孔令春 posted @ 2010年4月01日 07:08 in 网络安全 with tags 安装asio , 6458 阅读

首先将源

deb http://cz.archive.ubuntu.com/ubuntu karmic main 

添加到/etc/apt/sources.list文件中,然后就可以安装了,命令:

sudo apt-get install libasio-dev

卸载:

sudo apt-get remove libasio-dev

 

编译asio手册中的第一个例子 timer.cpp

//
// timer.cpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <iostream> #include <asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> int main() { asio::io_service io; asio::deadline_timer t(io, boost::posix_time::seconds(5)); t.wait(); std::cout << "Hello, world!\n"; return 0; }

g++ timer.cpp -o timer

结果出错,错误信息:

/tmp/ccRJNtHt.o: In function `asio::detail::posix_thread::~posix_thread()':
timer.cpp:(.text._ZN4asio6detail12posix_threadD1Ev[asio::detail::posix_thread::~posix_thread()]+0x1d): undefined reference to `pthread_detach'
/tmp/ccRJNtHt.o: In function `asio::detail::posix_thread::join()':
timer.cpp:(.text._ZN4asio6detail12posix_thread4joinEv[asio::detail::posix_thread::join()]+0x25): undefined reference to `pthread_join'
/tmp/ccRJNtHt.o: In function `asio::detail::posix_tss_ptr<asio::detail::call_stack<asio::detail::task_io_service<asio::detail::epoll_reactor<false> > >::context>::~posix_tss_ptr()':
timer.cpp:(.text._ZN4asio6detail13posix_tss_ptrINS0_10call_stackINS0_15task_io_serviceINS0_13epoll_reactorILb0EEEEEE7contextEED2Ev[asio::detail::posix_tss_ptr<asio::detail::call_stack<asio::detail::task_io_service<asio::detail::epoll_reactor<false> > >::context>::~posix_tss_ptr()]+0xf): undefined reference to `pthread_key_delete'
/tmp/ccRJNtHt.o: In function `asio::detail::posix_tss_ptr<asio::detail::call_stack<asio::detail::task_io_service<asio::detail::epoll_reactor<false> > >::context>::posix_tss_ptr()':
timer.cpp:(.text._ZN4asio6detail13posix_tss_ptrINS0_10call_stackINS0_15task_io_serviceINS0_13epoll_reactorILb0EEEEEE7contextEEC2Ev[asio::detail::posix_tss_ptr<asio::detail::call_stack<asio::detail::task_io_service<asio::detail::epoll_reactor<false> > >::context>::posix_tss_ptr()]+0x22): undefined reference to `pthread_key_create'
collect2: ld returned 1 exit status
 

看了半天才看明白,原来是缺少多线程,指定参数-lpthread再编译之后成功,命令:

g++ timer.cpp -o timer -lpthread

Avatar_small
Bluehost Webmail Log 说:
2022年8月08日 00:25

Blue host Webmail lets the individual create their professional and personalized email address. Having a business or personal brand does require a personalized email address, which increases more credibility. The attraction from customers will be more when you use your business related or personal name in the mail instead of using @outlook or @gmail. Bluehost Webmail Login There are options under Blue host Webmail that allow users to create personal email without actually creating a website. The Blue host Webmail control panel allows you to create multiple emails with a user-friendly option to access the same.

Avatar_small
Bihar Board Question 说:
2022年9月12日 22:55

Bihar State Vidyalay Pariksha Samiti, Patna Board (Bihar State School Examination Board) and others have designed and suggested the State Elementary Level Primary Education Class 3nd Grade study & learning material as Bihar Board 3rd Class Model Paper 2023 with Mock Test and Practice Questions. Bihar Board Question Paper Class 3 All Regional Students of Bihar Board can download the BSEB STD-3 Question Paper 2023 Pdf to All Languages ​​and Subjects for SCERT & NCERT Syllabus students of Hindi Medium, English Medium and Urdu Medium Students Studding in Government & Private Schools of the State & Central Board.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter