【发布时间】:2025-12-05 21:20:04
【问题描述】:
假设我使用 CentOS 7 和 GCC 7 来编译一个静态库(我们称之为 mylib.a),我想在 CentOS 6(使用旧系统库)上使用它(编译后)。
最好的方法是什么?静态链接到 libstdc++ 等?还有什么?
目前,当我针对我的静态库 mylib.a 构建(在 CentOS 6 上使用 gcc 4.x)可执行文件时,我得到了类似的结果:
/opt/boost/boost/date_time/gregorian/gregorian_io.hpp:62: undefined reference to `operator delete(void*, unsigned long)'
mylib.a([myFile].o): In function `std::locale::locale<boost::date_time::date_facet<boost::gregorian::date, char, std::ostreambuf_iterator<char, std::char_traits<char> > > >(std::locale const&, boost::date_time::date_facet<boost::gregorian::date, char, std::ostreambuf_iterator<char, std::char_traits<char> > >*)':
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/locale_classes.tcc:47: undefined reference to `operator delete(void*, unsigned long)'
我怀疑这是因为 boost_date_time.a 在没有最新开发工具的情况下在 CentOS 7 上使用 gcc 4.x 构建时不是针对 libstdc++.a 构建的。
想过吗?
谢谢!
【问题讨论】:
-
您是在询问实际的静态库,还是使用静态库的应用程序?如果是第一种,如何为不同的目标提供单独的静态库文件?
-
当我针对构建在不同操作系统上的 mylib.a 构建可执行文件时,会出现上述错误。
-
@hyde 我不是构建专家,所以我不确定如何为不同的系统设置多个目标。听起来我需要多个虚拟机?我的要求很简单——用 gcc 7 + centos 7 构建 mylib.a,然后用 gcc 4.x + centos 6 构建可执行文件并在那里运行。
-
不,你不需要虚拟机,你只需要不同的工具链
-
交叉编译它。