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) 静态库和动态库共 ...
随机推荐
- [转载]Go的50度灰:Golang新开发者要注意的陷阱和常见错误
初级 开大括号不能放在单独的一行 未使用的变量 未使用的Imports 简式的变量声明仅可以在函数内部使用 使用简式声明重复声明变量 偶然的变量隐藏Accidental Variable Shadow ...
- iOS设计模式 —— KV0
刨根问底KVO KVO 全称 Key-Value Observing.中文叫键值观察.KVO其实是一种观察者模式,观察者在键值改变时会得到通知,利用它可以很容易实现视图组件和数据模型的分离,当数据模型 ...
- springmvc Converter
以下,来自于Springmvc指南第二版,第93页. Spring的Converter是可以将一种类型转为另一种类型. 例如用户输入的date类型可能有多种格式. 比如:在controller中接收一 ...
- Java常见知识点(二)
21.常量池专门用于管理在编译时被确定并被保存在已编译的.class文件中的一些数据.它包括了关于类.方法.接口中的常量,还包括字符串常量. 22.String已经重写了Object的equals ...
- Selenium2+python自动化60-异常后截图(screenshot)【转载】
前言 在执行用例过程中由于是无人值守的,用例运行报错的时候,我们希望能对当前屏幕截图,留下证据. 在写用例的时候,最后一步是断言,可以把截图的动作放在断言这里,那么如何在断言失败后截图呢? 一.截图方 ...
- Android 曲线动画animation,类似加入购物车动画
按照惯例先放效果图:图中小球做抛物线运动 资源图片 1.首先布局文件activity_main.xml,布局很简单,就一个测试按钮 <RelativeLayout xmlns:android=& ...
- AC日记——平衡树练习 codevs 4244
4244 平衡树练习 思路: 有节操的人不用set也不用map: 代码: #include <cstdio> #include <cstring> #include <i ...
- [libgdx游戏开发教程]使用Libgdx进行游戏开发(9)-场景过渡
本章主要讲解场景过渡效果的使用.这里将用到Render to Texture(RTT)技术. Libgdx提供了一个类,实现了各种常见的插值算法,不仅适合过渡效果,也适合任意特定行为. 在本游戏里面, ...
- Python:文件操作技巧(File operation)(转)
Python:文件操作技巧(File operation) 读写文件 # ! /usr/bin/python # -*- coding: utf8 -*- spath = " D:/dow ...
- 2017中国大学生程序设计竞赛 - 女生专场A【模拟】
A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...