我在哪里放置第三方库来建立C ++ Linux开发环境? [英] Where do I put third-party libraries to set up a C++ Linux development environment?

查看:174
本文介绍了我在哪里放置第三方库来建立C ++ Linux开发环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我是Linux的新手,但我对C ++并不陌生.我正在使用CMake来预编译带有某些第三方组件的跨平台游戏引擎,但是我对使用库存在很多疑问.我的问题是如何使用第三方库以及将它们放在哪里. Apt将libs安装在其官方位置(/usr/local,/usr/lib/..),但是我在Windows中使用项目目录中文件夹中的本地libs进行开发.

I'm not new in C++ although I'm new in Linux. I'm using CMake to precompile a cross-platform game engine with some third-party components, but I have a lot of doubts about using libraries. My question is how to work with third-party libraries and where to put them. Apt installs libs in their official place (/usr/local, /usr/lib/ ..) but I develop in Windows using local libs that are in a folder in my project dir.

此外,我需要一个很好的教程来了解库工作方式的规则.例如:当尝试编译我的项目时,luabind要求提供liblua.s0.1,但是AFAIK无法使用Lua提供的源生成该库(至少进行make,make install).

Also, I need a good tutorial to know the rules of how libraries work. For example: when trying to compile my project, luabind is asking for liblua.s0.1, but AFAIK there is no way to generate this library with the source provided by Lua (at least doing make, make install).

我知道,这个问题很模糊,但是我没有足够的经验来简化.

I know, this question is fuzzy but I haven't enough experience to be more concise.

更新:阅读了一些答案之后,下面是一个更为简洁的问题.如果安装了所有第三方库,如何分发程序?如何在不使用大量自述文件的情况下管理依赖项?

Update: After reading some answers, a more concise question is the following. If I install all third-party libraries, how can I distribute my program? How do I manage dependencies without using a large readme?

推荐答案

放置库的位置

最好的解决方案是尽可能使用Linux发行版的打包系统(apt-getyum或类似版本)从发行版提供的软件包中安装库.

The best solution is to use your Linux distribution's packaging system (apt-get, yum, or similar) to install libraries from distro-provided packages wherever possible.

如果发行版的打包库版本不够新,或者您需要一些非标准的构建选项,或者您需要发行版不提供的库,那么您可以自己构建和安装它.对于将库放置在何处,有两个主要选择:

If the distro's packaged libraries aren't of a recent enough version, or if you need some nonstandard build options, or if you need a library that your distro doesn't provide, then you can build and install it yourself. You have two main options for where to put the library:

  • /usr/local(/usr/local/lib下的库,/usr/local/include下的头).这将在整个系统范围内安装库,这可能是最简单的解决方案,因为您应该可以在不进行任何额外步骤的情况下针对它们进行构建.不要直接在/usr下安装库,因为这会干扰发行版的打包系统.
  • 在项目目录下,就像在Windows下一样.这样做的优点是不需要root用户访问权限,也不需要进行系统范围的更改,但是您必须更新项目的include路径和库路径,并且必须将所有共享库文件放在
  • /usr/local (libraries under /usr/local/lib, headers under /usr/local/include). This installs the libraries systemwide and is probably the simplest solution, since you should then be able to build against them without taking any extra steps. Do NOT install libraries directly under /usr, since that will interfere with your distro's packaging system.
  • Under your project directory, as you did under Windows. This has the advantages of not requiring root access and not making systemwide changes, but you'll have to update your project's include paths and library paths, and you'll have to put any shared library files someplace where the dynamic linker can find them (using LD_LIBRARY_PATH or ld.so.conf - see the link for more details).

库的工作方式

请参阅David A. Wheeler出色的编程库HOWTO .我建议您阅读该文章,然后将任何特定的问题发布为新主题.

See David A. Wheeler's excellent Programming Library HOWTO. I'd recommend reading that then posting any specific questions as new topics.

如何分发程序

传统上,Unix/Linux程序不包括其依赖项的副本.而是由最终用户或开发人员自行安装这些依赖项.正如您所说,这可能需要大型自述文件",但它有一些优点:

Traditionally, Unix / Linux programs do not include copies of their dependencies. It's instead up to the end user or developer to install those dependencies themselves. This can require a "large README," as you said, but it has a few advantages:

  • 开发库可以通过发行版的程序包管理器进行安装,管理和更新,而不是每个源副本都具有自己的要跟踪的库集.
  • 系统上任何给定库的只有一个副本,因此,例如,如果发现安全漏洞,则仅需要更新一个地方. (例如,请考虑一下在使用非常广泛的压缩库 zlib )时发现的混乱情况. 安全漏洞,因此每个包含受影响版本的应用程序都需要更新.)
  • 如果您的程序足够流行(并且是开源的,或者至少是免费提供的),则各种Linux发行版的软件包维护者可能希望对其进行打包并将其包含在其发行版中.软件包维护者真的不喜欢捆绑的库.例如,请参见有关该主题的Fedora页面.
  • Development libraries can be installed, managed, and updated via the distro's package manager, instead of each source copy having its own set of libraries to track.
  • There's only one copy of any given library on a system, so there's only one place that needs updating if, for example, a security flaw is found. (For example, consider the chaos that resulted when zlib, a very widely used compression library, was found to have a security flaw, so every application that included an affected version needed to be updated.)
  • If your program is popular enough (and is open source or at least freely available), then package maintainers for various Linux distributions may want to package it and include it in their distro. Package maintainers really don't like bundled libraries. See, for example, Fedora's page on the topic.

如果要将程序分发给最终用户,则可能要考虑提供一个软件包(.dpkg.rpm),他们可以简单地下载并安装它们而不必使用源代码.从最终用户的角度来看,理想情况下,应将软件包添加到发行版的存储库中(如果它是开源的,或者至少是免费提供的),以便用户可以使用其软件包管理器(apt-getyum)下载它.由于那里有大量的Linux发行版,这一切都可能变得复杂,但是与Debian/Ubuntu兼容的.dpkg和与Red Hat/CentOS/Fedora兼容的.rpm应该可以覆盖大量的最终用户.构建软件包并不难,并且在线上有很好的howtos.

If you're distributing your program to end users, you may want to consider offering a package (.dpkg or .rpm) that they could simply download and install without having to use source. Ideally, from the end user's perspective, the package would be added to distros' repositories (if it's open source or at least freely available) so that users can download it using their package managers (apt-get or yum). This can all get complicated, because of the large number of Linux distros out there, but a Debian/Ubuntu compatible .dpkg and a Red Hat/CentOS/Fedora-compatible .rpm should cover a good percentage of end users. Building packages isn't too hard, and there are good howtos online.

这篇关于我在哪里放置第三方库来建立C ++ Linux开发环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆