昨天编译去年写的FloorServer,居然一堆错误:

chu@chu-laptop:/media/E/work/github/FloorServer/FloorServer$ make
g++ -g -lboost_thread -lboost_date_time main.cpp -o FloorServer
In file included from WorkThread.h:14:0,
from Server.h:15,
from main.cpp:2:
Message.h:18:8: 警告: #endif 指示的末尾有多余的标识符 [默认启用]
In file included from Server.h:13:0,
from main.cpp:2:
SocketManager.h: 在构造函数‘SocketManager::SocketManager()’中:
SocketManager.h:23:12: 警告: 扩展初始值设定列表只在 -std=c++0x 或 -std=gnu++0x 下可用 [默认启用]
/tmp/cclzUKo9.o: In function `pre_exit(int, int)':
/media/E/work/github/FloorServer/FloorServer/debug.h:18: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/debug.h:22: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/debug.h:37: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `CheckConfigure()':
/media/E/work/github/FloorServer/FloorServer/main.cpp:29: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/main.cpp:44: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o:/media/E/work/github/FloorServer/FloorServer/main.cpp:52: more undefined references to `boost::this_thread::get_id()' follow
/tmp/cclzUKo9.o: In function `thread_data_base':
/usr/include/boost/thread/pthread/thread_data.hpp:67: undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/cclzUKo9.o: In function `interruption_checker':
/usr/include/boost/thread/pthread/thread_data.hpp:96: undefined reference to `boost::detail::get_current_thread_data()'
/tmp/cclzUKo9.o: In function `TaskQueue::Push(int)':
/media/E/work/github/FloorServer/FloorServer/TaskQueue.h:92: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/TaskQueue.h:96: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/TaskQueue.h:104: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `SocketManager::UpdateActiveTime(int)':
/media/E/work/github/FloorServer/FloorServer/SocketManager.h:33: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/SocketManager.h:38: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o:/media/E/work/github/FloorServer/FloorServer/Listener.h:37: more undefined references to `boost::this_thread::get_id()' follow
/tmp/cclzUKo9.o: In function `ThreadPool::StopAll()':
/media/E/work/github/FloorServer/FloorServer/WorkThread.h:167: undefined reference to `boost::thread::join()'
/media/E/work/github/FloorServer/FloorServer/WorkThread.h:169: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `Server::DestoryServer(Server*)':
/media/E/work/github/FloorServer/FloorServer/Server.h:45: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/Server.h:52: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `Server::Run()':
/media/E/work/github/FloorServer/FloorServer/Server.h:62: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `Server::Stop()':
/media/E/work/github/FloorServer/FloorServer/Server.h:71: undefined reference to `boost::this_thread::get_id()'
/media/E/work/github/FloorServer/FloorServer/Server.h:73: undefined reference to `boost::thread::join()'
/media/E/work/github/FloorServer/FloorServer/Server.h:77: undefined reference to `boost::thread::join()'
/media/E/work/github/FloorServer/FloorServer/Server.h:78: undefined reference to `boost::this_thread::get_id()'
/tmp/cclzUKo9.o: In function `bool boost::condition_variable_any::timed_wait<boost::unique_lock<boost::mutex> >(boost::unique_lock<boost::mutex>&, boost::posix_time::ptime const&)':
/usr/include/boost/thread/pthread/condition_variable.hpp:148: undefined reference to `boost::this_thread::interruption_point()'
/tmp/cclzUKo9.o: In function `thread<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Worker>, boost::_bi::list1<boost::_bi::value<Worker*> > > >':
/usr/include/boost/thread/detail/thread.hpp:204: undefined reference to `boost::thread::start_thread()'
/tmp/cclzUKo9.o: In function `thread<void (Listener::*)(), Listener*>':
/usr/include/boost/thread/detail/thread.hpp:252: undefined reference to `boost::thread::start_thread()'
/tmp/cclzUKo9.o: In function `thread<void (SocketManager::*)(), SocketManager*>':
/usr/include/boost/thread/detail/thread.hpp:252: undefined reference to `boost::thread::start_thread()'
/tmp/cclzUKo9.o: In function `void boost::checked_delete<boost::thread>(boost::thread*)':
/usr/include/boost/checked_delete.hpp:34: undefined reference to `boost::thread::~thread()'
/tmp/cclzUKo9.o: In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)':
/usr/include/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
/usr/include/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
/tmp/cclzUKo9.o: In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_extended_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)':
/usr/include/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
/usr/include/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
/tmp/cclzUKo9.o: In function `~thread_data':
/usr/include/boost/thread/detail/thread.hpp:40: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/include/boost/thread/detail/thread.hpp:40: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/include/boost/thread/detail/thread.hpp:40: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/cclzUKo9.o:(.rodata._ZTIN5boost6detail11thread_dataINS_3_bi6bind_tIvNS_4_mfi3mf0Iv13SocketManagerEENS2_5list1INS2_5valueIPS6_EEEEEEEE[typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, SocketManager>, boost::_bi::list1<boost::_bi::value<SocketManager*> > > >]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'
/tmp/cclzUKo9.o:(.rodata._ZTIN5boost6detail11thread_dataINS_3_bi6bind_tIvNS_4_mfi3mf0Iv8ListenerEENS2_5list1INS2_5valueIPS6_EEEEEEEE[typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Listener>, boost::_bi::list1<boost::_bi::value<Listener*> > > >]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'
/tmp/cclzUKo9.o:(.rodata._ZTIN5boost6detail11thread_dataINS_3_bi6bind_tIvNS_4_mfi3mf0Iv6WorkerEENS2_5list1INS2_5valueIPS6_EEEEEEEE[typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Worker>, boost::_bi::list1<boost::_bi::value<Worker*> > > >]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld 返回 1
make: *** [FloorServer] 错误 1

从错误信息看,是boost thread库没有找到,导致链接失败。

但是经过确认,系统中的boost库是没有问题的,libboost_thread.a是导出了相应的符号的:

chu@chu-laptop:/media/E/work/github/FloorServer/FloorServer$ nm /usr/lib/libboost_thread.a |grep get_id
000014b0 T _ZN5boost11this_thread6get_idEv
00000440 T _ZNK5boost6thread6get_idEv
chu@chu-laptop:/media/E/work/github/FloorServer/FloorServer$ nm /usr/lib/libboost_thread.a |grep thread_data_base
00000000 W _ZN5boost23enable_shared_from_thisINS_6detail16thread_data_baseEED1Ev
00000000 W _ZN5boost23enable_shared_from_thisINS_6detail16thread_data_baseEED2Ev
00000000 n _ZN5boost23enable_shared_from_thisINS_6detail16thread_data_baseEED5Ev
00002bc0 T _ZN5boost6detail16thread_data_baseD0Ev
00002a70 T _ZN5boost6detail16thread_data_baseD1Ev
00002a70 T _ZN5boost6detail16thread_data_baseD2Ev

既然库没有问题,那么只可能是编译命令出错了。

对比其他项目的Makefile,发现这样像下面这样写能够编译通过:

g++ -o aimuserver main.o libcrypto.a -lboost_thread -lboost_date_time

于是尝试修改编译命令,将链接库放在最后,输出目标放在最前:

g++ -g -o FloorServer main.cpp -lboost_thread -lboost_date_time

最后也编译通过了。

看来以后写Makefile时最好遵守:g++ -o output  source.cpp -lboost_thread 的形式。

g++ 链接静态库命令应该放在最后的更多相关文章

  1. [转]Linux下用gcc/g++生成静态库和动态库(Z)

    Linux下用gcc/g++生成静态库和动态库(Z) 2012-07-24 16:45:10|  分类: linux |  标签:链接库  linux  g++  gcc  |举报|字号 订阅     ...

  2. gcc/g++链接时.o文件及库的顺序问题

    折腾gcc/g++链接时.o文件及库的顺序问题 链接静态库的顺序问题 GCC 编译使用动态链接库和静态链接库--及先后顺序----及环境变量设置总结

  3. linux下 GCC编译链接静态库&动态库

    静态库 有时候需要把一组代码编译成一个库,这个库在很多项目中都要用到,例如libc就是这样一个库, 我们在不同的程序中都会用到libc中的库函数(例如printf),也会用到libc中的变量(例如以后 ...

  4. Linux gcc/g++链接编译顺序详解

    gcc/g++链接时对库的顺序要求 -Ldir Add directory dir to the list of directories to be searched for -l. -llibrar ...

  5. 折腾gcc/g++链接时.o文件及库的顺序问题(转)

    转自: http://www.cnblogs.com/OCaml/archive/2012/06/18/2554086.html#sec-1-1 折腾gcc/g++链接时.o文件及库的顺序问题 Tab ...

  6. 折腾gcc/g++链接时.o文件及库的顺序问题

    gcc/g++链接时.o文件以及库的顺序问题 1 写在前面 最近换了xubuntu12.4,把原来的项目co出来编译的时候报"undefined reference to".猜测是 ...

  7. iOS 解压打包静态库命令

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Hannotate SC" } p.p2 { margin: 0.0px ...

  8. Unix环境链接静态库

    静态库 请点评 有时候需要把一组代码编译成一个库,这个库在很多项目中都要用到,例如libc就是这样一个库,我们在不同的程序中都会用到libc中的库函数(例如printf),也会用到libc中的变量(例 ...

  9. cmake 强制链接静态库

    add_executable(main main.cpp) target_link_libraries(main ${CMAKE_SOURCE_DIR}/libbingitup.a) 静态库和动态库共 ...

随机推荐

  1. a标签里文本居中

    text-align:center; height: 30px; line-height:30px;

  2. python基础复习-1-1文件类型、变量、运算符、表达式

    文件类型: .py python源文件 由python解释器执行 .pyc python源码编译后生成的文件(字节代码) 编译方法: 源码文件中使用py_compile模块 import py_com ...

  3. 根据流程实例ID获取当前任务

    JAVA: Task task = this.processEngine.getTaskService().createTaskQuery().processInstanceId(“132501”). ...

  4. w3cschool javascript学习

    name与Id属性区别 1.我们知道在网页做Post提交时,是以Form(即表单域)为单位进行提交的,一个Form里有若干个表单对象(如<input type="text" ...

  5. 【cocos2d-js官方文档】四、基础数据类型

    基础数据类型统一通过方法来创建.不再支持new方式 1.坐标cc.Point 一共3种创建方式 结构:{x:0,y:0} //1 快捷创建,返回相当于cc.p(0,0) var point1 = cc ...

  6. Codeforces 811 C. Vladik and Memorable Trip

    C. Vladik and Memorable Trip   time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  7. (22)python 自动化

    例子 from selenium import webdriver driver = webdriver.PhantomJS() driver.get("http://www.huhumh. ...

  8. (9)python 异常

    以下程序是python2版本下测试的代码 一.内置异常 没有错误信息的普通异常 raise Exception 添加错误信息的异常 raise Exception ('...错误') 内建异常 异常名 ...

  9. HDU 5938 Four Operations 【字符串处理,枚举,把数字字符串变为数值】

    Problem Description Little Ruins is a studious boy, recently he learned the four operations! Now he ...

  10. JavaScript代码放在head和body的区别(QRCode生成)

    1.在head中时,所代表的functions只加载而不执行,执行是在某一事件触发后才开始. 2.在body中时,直接加载并执行 典型的区别: 如果有不在函数中的执行语句,比如变量初始化,如果在hea ...