g++ 链接静态库命令应该放在最后
昨天编译去年写的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++ 链接静态库命令应该放在最后的更多相关文章
- [转]Linux下用gcc/g++生成静态库和动态库(Z)
Linux下用gcc/g++生成静态库和动态库(Z) 2012-07-24 16:45:10| 分类: linux | 标签:链接库 linux g++ gcc |举报|字号 订阅 ...
- gcc/g++链接时.o文件及库的顺序问题
折腾gcc/g++链接时.o文件及库的顺序问题 链接静态库的顺序问题 GCC 编译使用动态链接库和静态链接库--及先后顺序----及环境变量设置总结
- linux下 GCC编译链接静态库&动态库
静态库 有时候需要把一组代码编译成一个库,这个库在很多项目中都要用到,例如libc就是这样一个库, 我们在不同的程序中都会用到libc中的库函数(例如printf),也会用到libc中的变量(例如以后 ...
- Linux gcc/g++链接编译顺序详解
gcc/g++链接时对库的顺序要求 -Ldir Add directory dir to the list of directories to be searched for -l. -llibrar ...
- 折腾gcc/g++链接时.o文件及库的顺序问题(转)
转自: http://www.cnblogs.com/OCaml/archive/2012/06/18/2554086.html#sec-1-1 折腾gcc/g++链接时.o文件及库的顺序问题 Tab ...
- 折腾gcc/g++链接时.o文件及库的顺序问题
gcc/g++链接时.o文件以及库的顺序问题 1 写在前面 最近换了xubuntu12.4,把原来的项目co出来编译的时候报"undefined reference to".猜测是 ...
- iOS 解压打包静态库命令
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Hannotate SC" } p.p2 { margin: 0.0px ...
- Unix环境链接静态库
静态库 请点评 有时候需要把一组代码编译成一个库,这个库在很多项目中都要用到,例如libc就是这样一个库,我们在不同的程序中都会用到libc中的库函数(例如printf),也会用到libc中的变量(例 ...
- cmake 强制链接静态库
add_executable(main main.cpp) target_link_libraries(main ${CMAKE_SOURCE_DIR}/libbingitup.a) 静态库和动态库共 ...
随机推荐
- SuSE Linux10.1 网络设置以及和主机通信end
设置步骤如下: 1.首先判断VMware Bridge Protocol协议是否已经安装.在本地连接的属性中可以查看. 2.虚拟机设置为bridged 3. 虚拟机-Edit-Virtual Netw ...
- sql文格式替换
SELECT COUNT(1)FROM TAB1 TWHERE T.IS_DEL <> 0 将以上SQL格式替换为代码中的格式 sql.AppendLine(" SELECT & ...
- 关于easyui checkbox 的一些操作处理
1.easyui在每一行加checkbox { field: 'id', title: '编号', checkbox: true } 2.easyui分页时记住前面已选的checkbox 设置easy ...
- 【计算机网络】wireshark抓包分析1
学习计算机网络很久了,但总是局限于书本知识,感觉get不到重点.经师兄建议用wireshark抓包分析看看. 我自己以前并没有做过抓包分析,所以这篇博文可能会有很多错误,只是我自己的一个记录,路过的亲 ...
- Tkinter 计算器
from tkinter import * master = Tk() frame = Frame(master) frame.pack(padx=10,pady=10) v1 = StringVar ...
- 使用chardet模块判断网页编码
import chardet import urllib.request url='http://stock.sohu.com/news/' html = urllib.request.urlopen ...
- 实例解析嵌套的JSON格式数据
关于JSON数据格式的基本知识和概念,参看: http://www.cnblogs.com/zouzf/archive/2012/03/31/2426646.html <span style=& ...
- [thinkphp] ajaxReturn案例
javascript: <script> $('.ajax-post').click(function(){ var action_url=$('form').attr('action') ...
- BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6881 Solved: 4213[Submit][Sta ...
- HDU 1181.变形课-并查集
变形课 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submis ...