[英]Distribute a C++ application (game) on Linux: shared or static libraries?
I have a C++ game/application which use several libraries: OpenGL, OpenAL, Curl, Freetype2, GLFW, etc. Should I distribute my C++ binary application on Linux using the shared libraries or should I link them statically?我有一个 C++ 游戏/应用程序,它使用多个库:OpenGL、OpenAL、Curl、Freetype2、GLFW 等。我应该使用共享库在 Linux 上分发我的 C++ 二进制应用程序,还是应该静态链接它们?
lddtree
)lddtree
检查) Did I miss something?我错过了什么? Note: on Windows, it is more simple: I can use shared libraries (*.dll) and provide them with my application.
注意:在 Windows 上,它更简单:我可以使用共享库 (*.dll) 并在我的应用程序中提供它们。 On Linux, it seems quite difficult to provie the shared libraries.
在 Linux 上,似乎很难提供共享库。 Example: "libcurl-gnutls.so.4" depends of > 20 others shared libraries: it is not the case on Windows with "libcurl-x64.dll" which is self sufficient.
示例:“libcurl-gnutls.so.4”依赖于 > 20 个其他共享库:Windows 上的情况并非如此,“libcurl-x64.dll”是自给自足的。
I finally answer myself to my question after analyzed dozens of video games more.在分析了数十款电子游戏后,我终于回答了自己的问题。 There are mainly two categories:
主要有两类:
Games built with only static libraries.仅使用 static 个库构建的游戏。 Most of the time, it seems related to games using Unreal Engine.
大多数时候,它似乎与使用虚幻引擎的游戏有关。
Games built with shared libraries which are delivered with the game.使用随游戏交付的共享库构建的游戏。 The game starts via a bash script and use LD_LIBRARY_PATH to define the path to these shared libraries.
游戏通过 bash 脚本开始,并使用 LD_LIBRARY_PATH 定义这些共享库的路径。 Seems the best solution for me even if it is not the spirit of the shared libraries.
对我来说似乎是最好的解决方案,即使它不是共享库的精神。
Side notes:旁注:
I don't see a reason why your C++ shared library would necessarily be incompatible with different Ubutu releases, or why it would need to resort to LD_LIBRARY_PATH.我看不出为什么您的 C++ 共享库必然与不同的 Ubutu 版本不兼容,或者为什么它需要求助于 LD_LIBRARY_PATH。 Different releases (version numbers) of a shared library can co-exist in the system, and the program loader is able to search for the correct version based on ELF metadata annotated in the binary.
共享库的不同版本(版本号)可以在系统中共存,程序加载器可以根据二进制文件中注释的 ELF 元数据搜索正确的版本。 Moreover, GNU/Linux shared objects are equivalent to Windows DLLs for this purpose.
此外,为此,GNU/Linux 共享对象相当于 Windows 个 DLL。 If your code is portable, you may even use MinGW to build both.so and.dll objects from the same source file (GNU build system, aka Autotools may be of great help).
如果您的代码是可移植的,您甚至可以使用 MinGW 从同一个源文件构建 .so 和 .dll 对象(GNU 构建系统,又名 Autotools 可能会有很大帮助)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.