简体   繁体   English

在Linux上部署Qt应用程序二进制文件,与LSB兼容

[英]Deploy a Qt Application Binary on Linux, compatible with LSB

I have developed a small application in Qt Creator on Ubuntu 12.04 which I want should run on any other linux distro (mostly different versions of CentOS and ubuntu), just like any portable application on windows does. 我已经在Ubuntu 12.04上的Qt Creator中开发了一个小型应用程序,希望它可以在其他任何Linux发行版(大多数版本的CentOS和ubuntu)上运行,就像Windows上的任何便携式应用程序一样。

I want to be able to simply share the binary file of the Application, and run the application. 我希望能够简单地共享应用程序的二进制文件,然后运行该应用程序。 I am able to successfully do this in windows, by just building the project in QT Creator and then putting the required libraries in the Application directory and then transfering them to other windows systems. 通过在QT Creator中构建项目,然后将所需的库放在Application目录中,然后将它们转移到其他Windows系统中,我能够在Windows中成功完成此操作。

I searched all over and found out that I should be trying to build the project using LSB(Linux Standard Base) Compatibility, so that it runs on other linux distros. 我到处搜索,发现我应该尝试使用LSB(Linux标准库)兼容性来构建该项目,以便它可以在其他Linux发行版上运行。 Is that the right way to do this? 这是正确的方法吗?

I am very new to Qt and also to Linux (dont know much of Shell Scripting). 我对Qt和Linux都是新手(对Shell脚本了解不多)。 Thus, I dont know how I should proceed to make the Application LSB Compliant. 因此,我不知道如何继续使该应用程序LSB兼容。

I have refered to, the following links: Distributing Qt-based binaries on Linux and Deploying Qt applications on Linux but have not beem able to understand what I am suposed to do. 我已经参考了以下链接: 在Linux上分发基于Qt的二进制文件在Linux上 部署Qt应用程序,但是还无法理解我的工作。

I also found this question here which states a very similar situation as mine, but because I am a novice, I dont know how I should do this. 我还在这里发现了一个与我的情况非常相似的问题,但是由于我是新手,所以我不知道该怎么做。

Moreover, considering that the first two articles were written 6 years back, shouldn't there be a simpler way to deploy Qt apps on the linux platform now? 而且,考虑到前两篇文章是6年前写的,难道现在不应该有一种更简单的方法来在Linux平台上部署Qt应用程序吗? I also saw something about static linking, is that the way to go? 我还看到了一些有关静态链接的东西,这是可行的方法吗? Isn't there a way by which all of this can be done through Qt Creator itself? 是否没有办法可以通过Qt Creator本身完成所有这些工作?

If there is no hope of creating a portable Qt Application for Linux, then is there a way, say a shell script or something that would combine all the steps required to compile the Qt project on another computer and run it. 如果没有希望为Linux创建一个可移植的Qt应用程序,那么有一种方法,例如说一个shell脚本或某种可以组合在另一台计算机上编译Qt项目并运行它的步骤。 Say, download Qt-SDK if not present, run qmake and make and then the newly compiled application, if not already there, so that the user can run the program just by running one script. 比如说,下载Qt-SDK(如果不存在的话),运行qmake和make,然后运行新编译的应用程序(如果还没有的话),以便用户可以仅通过运行一个脚本来运行该程序。

Making a binary application compatible with any other Linux distro is practically impossible since you will never know in advance which libraries are available in distro X, or what version of that library is available. 实际上,使二进制应用程序与任何其他 Linux发行版兼容几乎是不可能的,因为您永远不会事先知道发行版X中可用的库或该库的哪个版本。 Even among a single distro (eg Ubuntu), binary application are almost never backward-compatible, since anything built on Ubuntu 12.04 will have dependencies on versions libraries which are installed on that version of Ubuntu, and trying to run that binary on Ubuntu 10.04 will most probably fail simply because it doesn't have a recent enough version of glibc or some other necessary library. 即使在单个发行版(例如Ubuntu)中,二进制应用程序也几乎永远不会向后兼容,因为在Ubuntu 12.04上构建的任何东西都将依赖于该Ubuntu版本上安装的版本库,并且尝试在Ubuntu 10.04上运行该二进制文件将最有可能失败的原因仅仅是因为它没有最新版本的glibc或其他一些必要的库。

However, the idea can be much more implementable if you limit yourself to a finite list of distros and versions of those distros. 但是,如果您将自己限制在发行版的有限列表和发行版中,则该想法可能更加可行。 You can then know which libraries are available for those distros, and aim for the lowest common denominator. 然后,您可以知道哪些库可用于这些发行版,并以最低的公分母为目标。 I used to maintain a binary application which had to support several distros (Ubuntu, Fedora, OpenSUSE, SLED, Mandriva), and the way I would do it is install the oldest distro I was targeting on my build machine. 我曾经维护过一个二进制应用程序,该应用程序必须支持多个发行版(Ubuntu,Fedora,OpenSUSE,SLED,Mandriva),而我要做的方式是在构建机器上安装我所针对的最旧发行版。 That way, the binary application would be linked to the oldest versions of the libraries available on those distros. 这样,二进制应用程序将链接到这些发行版上可用的最旧版本的库。 Unless there's a new major version of such a library (which happens quite rarely, and even then, distros usually distribute the previous major version for a while for compatibility purposes), your compiled binary will then be compatible with all your targeted distros. 除非有这样一个库的新主版本(这种情况很少发生,即使如此,发行版通常也会出于兼容性目的而分发以前的主版本一段时间),然后编译的二进制文件才能与所有目标发行版兼容。

Therefore, the quick piece of advice I would give for your situation, use the oldest LTS version of Ubuntu which is still supported (10.04 at the moment) for your development, and you should be pretty safe for most recent popular distros. 因此,针对您的情况,我将给出一个简短的建议,使用仍受支持的最旧的LTS版本的Ubuntu(目前为10.04)进行开发,对于最近流行的发行版,您应该是相当安全的。 For the application you already developped on Ubuntu 12.04, you should have no problem simply recompiling the same source on 10.04. 对于已经在Ubuntu 12.04上开发的应用程序,只要在10.04上重新编译相同的源代码,就应该没有问题。 Understand that you will never however achieve 100% compatibility with a compiled C++ Qt application. 请理解,您将永远无法与已编译的C ++ Qt应用程序实现100%的兼容性。

If Qt is not all that important to you, you could use a higher-level or interpreted language such as Python, Java, Perl or Ruby. 如果Qt对您而言并不那么重要,则可以使用更高级别或解释性的语言,例如Python,Java,Perl或Ruby。 With such languages, you can usually count on the language implementation already being installed on the target distro. 使用此类语言,通常可以指望目标发行版中已安装的语言实现。

Your problem here is not the Linux Standard Base, but rather the presence or not of the specific version of Qt you need (or a later one). 您的问题不是Linux Standard Base,而是您是否需要特定版本的Qt(或更高版本)。

Exactly like on a Windows machine, a user may have any of Qt installed, or they may not have it at all. 就像在Windows计算机上一样,用户可能安装了任何Qt,或者根本没有安装。 On Windows it is easier to check for the presence of a certain version of Qt than it is on Linux, thus it is easier to write install tools that automate the experience. 在Windows上,比在Linux上检查某个版本的Qt的存在要容易得多,因此编写使体验自动进行的安装工具更加容易。

To solve your problem there are a few ways: 要解决您的问题,有几种方法:

  1. Inform the user that your program requires a certain version of Qt or higher, and let the user handle the problem 通知用户您的程序需要特定版本的Qt或更高版本,并让用户处理问题
  2. Learn how to create packages for every distribution you want to target and create specific packages 了解如何为要定位的每个发行版创建软件包以及创建特定的软件包
  3. Use a program like 0Install or Elf Statifier to create a package/executable containing all the necessary libraries. 使用0Install或Elf Statifier之类的程序来创建包含所有必需库的程序包/可执行文件。

The latter is similar to what many Windows and Mac programs do (they include every library they need within the installer), but it is not the preferred way on Linux, which relies heavily on shared libraries. 后者类似于许多Windows和Mac程序所做的工作(它们包括安装程序中所需的每个库),但这不是Linux上的首选方法,后者在很大程度上依赖于共享库。

Deploy an application in Linux is a nightmare, luckily there are some solutions. 在Linux中部署应用程序是一场噩梦,幸运的是,这里有一些解决方案。 Check this projects to build a portable binary with all their dependencies bundled: 检查以下项目以构建将所有依赖项捆绑在一起的可移植二进制文件:

http://statifier.sourceforge.net/statifier/main.html http://statifier.sourceforge.net/statifier/main.html

http://www.magicermine.com/index.html http://www.magicermine.com/index.html

http://www.pgbovine.net/cde.html http://www.pgbovine.net/cde.html

Another solution is make a portable 0install package: 另一个解决方案是制作便携式0install软件包:

http://0install.net/ http://0install.net/

I recomend this solution. 我推荐这种解决方案。 Personally I have been problems with the 3 first packagers. 就我个人而言,最初的三个打包程序都存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM