3

最近我问了一个问题,关于我应该使用什么来创建将部署在许多 Linux 发行版下的自包含可执行文件。一开始我很害怕,但是在阅读了一点 C++ 之后,我设法让我的可执行文件的第一个版本运行起来。

在充满欢乐的一天之后,我又一次陷入困境。生成的可执行文件必须安装在许多 Linux 发行版(Slackware、Arch、Ubuntu、Debian、CentOS 等)中,而我完全不知道如何实现它。我所知道的 CentOS 和基于 Debian 的操作系统都有包管理器,比如 apt 或 yum,但我不确定这些是否适用于我的情况。

我编写的代码依赖于几个库(更具体地说是RudeSocketyaml-cpp。有人告诉我,我将能够编译可执行文件并动态链接它,所以我只需要分发可执行文件。

碰巧我找不到 yaml-cpp 库的 .a 文件(仅适用于 RudeSocket)。到目前为止,这是我的问题:

起初,我使用动态链接,但是(显然)当我将可执行文件复制到另一个盒子时:

$ ./main
./main: error while loading shared libraries: libyaml-cpp.so.0.2: cannot open shared object file: No such file or directory

当尝试静态编译它时,我也得到一个错误(因为我没有我提到的 yaml-cpp .a 文件):

$ g++ main.cpp parse.cpp parse.h rudesocket-1.3.0/.libs/librudesocket.a -o main -static -L/usr/local/librudesocket-1.3.0/.libs/librudesocket.a(socket_connect_normal.o): In function `rude::sckt::Socket_Connect_Normal::simpleConnect(int&, char const*, int)':
/root/webbyget/sockets/rudesocket-1.3.0/src/socket_connect_normal.cpp:250: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/cc3cEVK1.o: In function `operator>>(YAML::Node const&, Job&)':
parse.cpp:(.text+0x1a83): undefined reference to `YAML::Node::size() const'
/tmp/cc3cEVK1.o: In function `handle_job(rude::Socket, char const*)':
parse.cpp:(.text+0x1b79): undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
parse.cpp:(.text+0x1bfd): undefined reference to `YAML::Node::Node()'
parse.cpp:(.text+0x1c10): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)'
parse.cpp:(.text+0x1dc6): undefined reference to `YAML::Node::size() const'
parse.cpp:(.text+0x1dee): undefined reference to `YAML::Node::~Node()'
parse.cpp:(.text+0x1e18): undefined reference to `YAML::Node::~Node()'
parse.cpp:(.text+0x1e37): undefined reference to `YAML::Parser::~Parser()'
parse.cpp:(.text+0x1e61): undefined reference to `YAML::Parser::~Parser()'
(...)

对我来说很明显 g++ 不能在不告诉它在哪里找到 yaml-cpp 的类的情况下静态编译它。

安装应该在没有人工干预的情况下以自动化方式进行,这一点非常重要。

所以我的问题真的是双重的:

  • 如何以针对所有这些发行版的最简单的方式分发这个编译的程序?

  • 这种问题有没有事实上的标准解决方案?

先感谢您,

费利佩。

4

4 回答 4

4

你可以试试这种技术。

于 2009-09-16T17:17:42.853 回答
0

Maybe The best solution for you is to use CMake.

CMake is cross-platform, open-source build system. It is a family of tools designed to build, test and package software. For Packaging, Mgb is right, CMake can easily be coupled with CPack.

KDE is using this solution and its a very good alternative to automake/autoconf.

于 2009-09-23T10:09:09.860 回答
0

如果您使用平台包管理器(.rpm 或 .deb),系统将为您检查共享库的正确版本,并在需要时下载它。

CPack可能是最简单的包生成器

于 2009-09-16T17:30:28.673 回答
0

有许多事实上的标准,但没有一个是标准化的。:( 如果你想分发一个编译的二进制文件,你可能想为每个你想要定位的平台制作一个包。生成一个 rpm 和一个 deb 可能会让你完成 90% 的工作。如果你想自动化构建过程中,autoconf/automake 仍然(可能)是最好的方法。

于 2009-09-13T22:09:25.960 回答