zoukankan      html  css  js  c++  java
  • 编译boost asio http/server 方法

    这段时间学习boost 的asio 编程,想编译asio自带的http/server的程序,无奈在网上根本找不到方法,只能自己摸索学习。

    登陆boost asio 的example 目录,(我 boost 安装在/opt目录下)

    cd /opt/boost_1_55_0/libs/asio/example/cpp03/http/server

    编译命令:

    g++ *.cpp -lboost_system -lpthread -I/usr/local/include/boost -L/usr/local/lib -o main

    我之前自己编译了一次简单的asio的程序,编译命令不需要加 –lpthread,详细参考博文:

    http://www.cnblogs.com/chenfool/p/3719428.html

    但编译http/server的程序,不加 –lpthread 命令会出现如下错误:

    /tmp/ccODZX6Y.o: In function `boost::asio::detail::posix_signal_blocker::posix_signal_blocker()':
    server.cpp:(.text._ZN5boost4asio6detail20posix_signal_blockerC2Ev[_ZN5boost4asio6detail20posix_signal_blockerC5Ev]+0x44): undefined reference to `pthread_sigmask'
    /tmp/ccODZX6Y.o: In function `boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()':
    server.cpp:(.text._ZN5boost4asio6detail20posix_signal_blockerD2Ev[_ZN5boost4asio6detail20posix_signal_blockerD5Ev]+0x2a): undefined reference to `pthread_sigmask'
    /tmp/ccODZX6Y.o: In function `boost::asio::detail::posix_thread::~posix_thread()':
    server.cpp:(.text._ZN5boost4asio6detail12posix_threadD2Ev[_ZN5boost4asio6detail12posix_threadD5Ev]+0x1d): undefined reference to `pthread_detach'
    /tmp/ccODZX6Y.o: In function `boost::asio::detail::posix_thread::join()':
    server.cpp:(.text._ZN5boost4asio6detail12posix_thread4joinEv[boost::asio::detail::posix_thread::join()]+0x25): undefined reference to `pthread_join'
    /tmp/ccODZX6Y.o: In function `boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
    server.cpp:(.text._ZN5boost4asio6detail12posix_thread12start_threadEPNS2_9func_baseE[boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)]+0x24): undefined reference to `pthread_create'
    collect2: ld returned 1 exit status

    可以看到,错误信息中说asio 的库中,有使用多线程的库,所以在编译时也必须同时声明使用pthread的库来编译。

    此编译命令同时也支持其余http/server?的编译。

    详细自己看。

  • 相关阅读:
    4、线程--线程同部
    3、线程--线程调度
    2、线程--线程之前的状态转换
    1、线程--Thread&Runnable创建线程
    5、JUC--实现 Callable 接口
    13、JUC--ForkJoinPool 分支/合并框架 工作窃取
    linux连接iscsi存储方法
    ORA-01031: insufficient privileges 错误解决
    【opatch打补丁】oracle10.2.0.5.0升级10.2.0.5.9 for linux
    错误 ORA-01102: cannot mount database in EXCLUSIVE mode 的处理方法
  • 原文地址:https://www.cnblogs.com/chenfool/p/3750007.html
Copyright © 2011-2022 走看看