linux – Boost静态链接
发布时间:2021-02-20 15:04:10 所属栏目:Linux 来源:互联网
导读:我在 Linux,GCC中使用Boost库.在安装和构建Boost之后,我发现使用Regex和Thread的程序使用了共享的Boost库.为了我的目的,我需要静态链接. 如何更改链接类型?我应该重建Boost,还是可以通过在我自己的项目或Boost配置文件中定义一些常量来设置链接类型? 只需添
我在
Linux,GCC中使用Boost库.在安装和构建Boost之后,我发现使用Regex和Thread的程序使用了共享的Boost库.为了我的目的,我需要静态链接.
解决方法只需添加静态到你的构建调用.这是一个快速示例会话:$cat boost_formatted_time.cpp #include <iostream> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp> using namespace boost::posix_time; using namespace std; int main(int argc,char **argv) { time_facet *facet = new time_facet("%d-%b-%Y %H:%M:%S"); cout.imbue(locale(cout.getloc(),facet)); cout << second_clock::local_time() << endl; } $g++ -o /tmp/bft_dyn boost_formatted_time.cpp -lboost_date_time $g++ -static -o /tmp/bft_stc boost_formatted_time.cpp -lboost_date_time $ls -lh /tmp/bft_* -rwxr-xr-x 1 edd edd 216K 2010-02-24 12:34 /tmp/bft_dyn -rwxr-xr-x 1 edd edd 1.5M 2010-02-24 12:34 /tmp/bft_stc $/tmp/bft_dyn 24-Feb-2010 12:34:55 $/tmp/bft_stc 24-Feb-2010 12:34:59 $ 请注意,静态二进制文件的动态链接变量是256MB,而216kb.所有这些都使用默认的Boost包进行Debian测试. (编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- LINUX入门:Redhat 7.2 中文显示及中文输入法设置
- LINUX入门:Linux RedHat无法安装软件问题(No p
- 如何在Linux上安排重启?
- linux快速清空文件 比如log日志
- linux – 无法从外部机器访问公开暴露的Docker容
- linux – 为什么clock_gettime(CLOCK_REALTIME,.
- linux – Bash“declare -A”在macOS上不起作用
- 直接访问linux framebuffer – copyarea
- IPC与imsg? OpenBSD和Linux的兼容性?
- linux – sysfs_create_file()和sysfs_create_gr
热点阅读