我有一个使用 Boost::Asio 作为套接字的程序。我几乎改变了 Boost 示例中的一些代码。该程序在 VS 中的编译和运行就像在 Windows 上一样。但是,当我在 Linux 上编译该程序并运行它时,出现段错误。
我发布了代码here
我用来编译它的命令是这样的:
c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include
-I/appl/htopopt/Linux_x86_64/boost_1_43_0/include
mpqs.cpp mpqs_polynomial.cpp mpqs_host.cpp -o mpqs_host
-L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl
-L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm
-L/appl/htopopt/Linux_x86_64/boost_1_43_0/lib -lboost_system
-lboost_thread -static -lpthread
通过注释掉代码,我发现由于以下行而出现段错误:
boost::asio::io_service io_service;
任何人都可以提供任何帮助,了解可能出现的问题(以及解决方案)吗?
谢谢!
编辑:我尝试将程序更改为最小示例,不使用其他库或 header ,仅使用 boost/asio.hpp:
#define DEBUG 0
#include <boost/asio.hpp>
int main(int argc, char* argv[]) {
boost::asio::io_service io_service;
return 0;
}
我还删除了其他库包含和编译链接,但是这个最小的示例仍然给我带来了段错误。
最佳答案
来自 -static
选项的 GCC 在线文档:
On systems that support dynamic linking, this prevents linking with the shared libraries.
Boost 可以支持纯静态链接,但前提是在操作系统包维护者构建它时以这种方式配置。您绝对确定应该使用这个标志吗?如果没有,请尝试在不使用该标志的情况下重新编译,看看是否可以解决问题。
关于c++ - Boost 程序无法在 Linux 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3065472/