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) 静态库和动态库共 ...
随机推荐
- Codeforces 362E Petya and Pipes 费用流建图
题意: 给一个网络中某些边增加容量,增加的总和最大为K,使得最大流最大. 费用流:在某条边增加单位流量的费用. 那么就可以2个点之间建2条边,第一条给定边(u,v,x,0)这条边费用为0 同时另一条边 ...
- nginx、apache、tomcat的区别
1.Apache Apache支持模块化,性能稳定,Apache本身是静态解析,适合静态HTML.图片等,但可以通过扩展脚本.模块等支持动态页面等. 缺点:配置相对复杂,自身不支持动态页面. 2.To ...
- linux sun/awt/X11GraphicsEnvironment 找不到错误
转载自:http://blog.csdn.net/bolg_hero/article/details/46594915 在Linux下,我们在用Java的图片包来处理图片时,经常遇到java.lang ...
- ORM-老师信息系统
老师信息管理 思考 三种方式创建多对多外键方式及其优缺点. 通过外键创建 (自定义第三张表,通过外键与其他两张表关联 但是不能用Django ORM 多对多操作的语法) class Class(mo ...
- Ubuntu-16.04安装Xdebug-2.2.5及相关介绍
Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况.在日常开发中,我们会使用如 print_r() var_dump()等函数来进行调 ...
- ubantu16.04服务器错误提示没有安装php_fileinfo扩展
如果你是安装的LNMP1.3full一键安装包,安装的是php5.6.22,你会遇到这个错误,解决方法也不难,请看如下: 不需要去下载扩展,只需要进入此fileinfo目录(我这里有多个版本5.6,7 ...
- AC日记——[Ahoi2013]作业 bzoj 3236
3236 思路: 莫队+树状数组维护: 代码: #include <cmath> #include <cstdio> #include <cstring> #inc ...
- CentOS系统挂载FAT32的U盘
Linux挂载U盘步骤如下 1:将U盘插入USB接口,检查是否插好 2:用fdisk命令检查分区和USB设备信息 [root@wgods ~]# fdisk -l Disk /dev/sda: 100 ...
- Jquery EasyUI选项卡-Tabs的使用方法
以下是easyUI的tabs的简单实用介绍. var e =$('#main').tabs('exists','accordion'); if(e==true){ $('#main').tabs(' ...
- MySQL的数据类型和建库策略详解
无论是在小得可怜的免费数据库空间或是大型电子商务网站,合理的设计表结构.充分利用空间是十分必要的.这就要求我们对数据库系统的常用数据类型有充分的认识.下面我就将我的一点心得写出来跟大家分享. 一.数字 ...