在哪里放置第三方库来设置一个c ++ linux开发环境? [英] Where to put third party libraries to setup a c++ linux development environment?

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

问题描述

我不是新的C ++,虽然我是新的Linux。我使用CMake与一些第三方预编译跨平台游戏引擎,但我对使用库有很多疑问。我的问题是如何与第三方库一起工作。和在哪里放这个libs。 Apt在他们的官方位置(/ usr / local,/ usr / lib / ..)安装libs,但是我在windows中使用在一个文件夹中的本地libs在我的项目dir中。



另外,我需要一个好的教程来了解图书馆的工作原理。例如:当试图编译我的项目时,luabind是通过liblua.s0.1,但是AFAIK没有办法生成这个库与lua提供的源(至少做make,make install)。



我知道,这个问题很模糊,但我没有足够的经验来更简洁。



更新:阅读sombe答案后,更简明的问题是以下。如果我安装所有第三方库,我如何分发我的程序?

$


感谢所有的强力文本 =h2_lin>解决方案

图书馆位置



最佳解决方案是使用您的Linux发行版包装系统( apt-get yum 或类似) p>

如果发行版的打包库不是最新版本,或者您需要一些非标准的构建选项,或者如果您需要一个您的发行版不提供的库,那么你可以自己构建和安装它。您可以在两个主要选项中选择放置库的位置:




  • / usr / local / usr / local / lib 下的库, / usr / local / include 下的标题)。这会在系统范围内安装库,并且可能是最简单的解决方案,因为您应该可以在不采取任何额外步骤的情况下构建它们。不要直接在 / usr 下安装库,因为这会干扰您的发行版包装系统。

  • 在您的项目目录下,在Windows下。这具有不需要root访问权限和不进行系统范围更改的优点,但是您必须更新项目的包含路径和库路径,并且您必须将任何共享库文件放在动态链接器可以找到它们(使用 LD_LIBRARY_PATH ld.so.conf - 有关详情,请参阅链接)。



图书馆的工作方式



请参阅David A. Wheeler的优秀编程库HOWTO 。我建议阅读,然后将任何具体问题作为新主题发布。



如何分发您的计划



传统上,Unix / Linux程序不包括其依赖项的副本。而是由最终用户或开发人员自己安装这些依赖项。这可能需要一个大README,如你所说,但它有几个优点:




  • 开发库可以安装,并通过distro的包管理器更新,而不是每个源副本都有自己的一组要跟踪的库。

  • 系统上只有一个给定库的一个副本,因此只有一个位置其需要更新,例如,如果发现安全缺陷。 (例如,考虑当 zlib (一种非常广泛使用的压缩库)发现有安全性缺陷,因此每个包含受影响版本的应用都需要更新。)

  • 如果您的程序流行足够(并且是开源或至少免费提供),那么各种Linux发行版的软件包维护人员可能希望将其打包并包含在其发行版中。软件包维护人员真的不喜欢捆绑的库。例如,请参阅 Fedora的主题页面



如果您将程序分发给最终用户,您可能需要考虑提供一个包( .dpkg .rpm ),他们可以简单地下载和安装,而不必使用源。理想情况下,从最终用户的角度来看,包将被添加到distros的存储库(如果它是开源的或至少是免费的),以便用户可以使用他们的包管理器( apt-get yum )。这可以变得复杂,因为大量的Linux发行版,但Debian / Ubuntu兼容 .dpkg 和一个红帽/ CentOS / Fedora兼容 .rpm 应该覆盖很大百分比的最终用户。建筑包不是太难,在线有很好的howtos。


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, but I have a lot of doubts about using libraries. My question is how to work with third party libraries. And where to put this libs. Apt installs libs in their official place (/usr/local, /usr/lib/ ..) but I develop in windows using local libs that are in a folder into my project dir.

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 by 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 sombe answers, a more concise question is the following. If I install all third party libraries, how do I could distribute my program? How to manage dependecies without using a large readme?

Thanks for all*strong text*

解决方案

Where to put libraries

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 (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).

How libraries work

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

How to distribute your program

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:

  • 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.

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天全站免登陆