只需添加
-static到您的构建调用即可。这是一个简单的示例会话:
$ 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_dyn24-Feb-2010 12:34:55$ /tmp/bft_stc24-Feb-2010 12:34:59$请注意,静态二进制文件的大小为1.5mb,而动态链接变量的样式表为216kb。所有操作都使用默认的Boost软件包在Debian测试中完成。



