简体   繁体   English

Linux编程环境配置

[英]Linux programming environment configuration

The other day I set up an Ubuntu installation in a VM and went to gather the tools and libraries I figured I would need for programming mostly in C++. 前几天我在VM中设置了一个Ubuntu安装,然后去收集我认为我主要用C ++编程所需的工具和库。

I had a problem though, where to put things such as 3rd party source libraries, etc. From what I can gather, a lot of source distributions assume that a lot of their dependencies are already installed in a certain location and assume that a lot of tools are also installed in particular locations. 我遇到了一个问题,在哪里放置第三方源库等等。从我可以收集的内容来看,许多源代码分发假设它们的很多依赖项已经安装在某个位置并假设很多工具也安装在特定位置。

To give an example of what I currently do on Windows, is I have a directory where I keep all source code. 举一个我目前在Windows上做的例子,我有一个目录,我保留所有源代码。 C:\\code . C:\\code In this directory, I have a directory for all 3rd party libraries, c:\\code\\thirdparty\\libs . 在这个目录中,我有一个所有第三方库的目录, c:\\code\\thirdparty\\libs This way I can easily set up relative paths for all of the dependencies of any projects I write or come across and wish to compile. 通过这种方式,我可以轻松地为我编写或遇到的任何项目的所有依赖项设置相对路径,并希望进行编译。 The reason I am interested in setting up a linux programming environment is that it seems that both the tool and library dependency problems have been solved efficiently making it easy for example to build OpenSSH from source. 我对建立Linux编程环境感兴趣的原因是,似乎工具和库依赖问题都得到了有效解决,例如从源代码构建OpenSSH很容易。

So what I was looking for was a decent convention I can use when I am trying to organize my projects and libraries on linux that is easy to maintain and easy to use. 因此,当我尝试在linux上组织我的项目和库时,我可以使用的是一个不错的约定,易于维护和易于使用。

Short answer: don't do a "heaps of code in local dir" thing. 简短的回答:不要做“本地目录中的大量代码”的事情。

Long answer: don't do a "heaps of code in local dir" thing, because it will be nightmare to keep up-to-date, and if you decide to distribute your code, it will be nightmare to package it for any decent distribution. 答案很长:不要做“本地目录中的大量代码”的事情,因为保持最新状态将是一场噩梦,如果你决定分发你的代码,将它包装成任何体面将是噩梦分配。

Whenever possible, stick to the libraries shipped in the distribution (ubuntu has 20000+ packets, it ought to have most of what you'll need prepackaged). 只要有可能,坚持分发中提供的库(ubuntu有20000+个数据包,它应该包含你需要预先包装的大部分内容)。 When there is not package, you caninstall by hand to /usr/local (but see above about upgrades and DONT do that). 如果没有包,您可以手动安装到/ usr / local(但请参阅上面有关升级的信息,并且不要这样做)。

Better, use "stow" or "installwatch" (or both) to install to per-library dirs (/usr/local/stow/libA-ver123) and then symlink files from there to /usr/local or /usr/ (stow does the simlinking part). 更好的是,使用“stow”或“installwatch”(或两者)安装到每个库目录(/ usr / local / stow / libA-ver123),然后将符号链接文件从那里安装到​​/ usr / local或/ usr /(stow)是simlinking部分)。 Or just package the lib for your distribution. 或者只是为您的发行版打包lib。

For libraries/includes... 对于图书馆/包括......

/usr/local/lib
/usr/local/include

Where possible code against the system/distro provided libraries. 尽可能针对系统/发行版提供的代码库。 This makes it easiest to ship a product on that distro. 这使得在该发行版上发布产品变得最简单。

However, if you are building a commercial application, because there are so many flavors of Linux distros that can mean you have to maintain a plethora of different application builds for each distro. 但是,如果您正在构建商业应用程序,因为有许多类型的Linux发行版可能意味着您必须为每个发行版维护大量不同的应用程序构建。 Which isn't necessarily a bad thing as it means you can more cleanly integrate with the distro's package management system. 这不一定是坏事,因为这意味着您可以更加干净地与发行版的软件包管理系统集成。

But in the case where you can't do that it should be fairly easy to download the source of each 3rd party dependency you have and integrate the building of that dependency into a static lib that is linked to your executable. 但是在你不能这样做的情况下,下载你拥有的每个第三方依赖项的来源应该相当容易,并将该依赖项的构建集成到链接到你的可执行文件的静态库中。 That way you know exactly what you're linking against but has the downside of bloating out your executable size. 这样你就可以准确地知道你所链接的内容,但却有可能缩小你的可执行文件大小。 This can also be required if you need a specific library (or version) not provided by the distro. 如果您需要发行版未提供的特定库(或版本),也可能需要这样做。

If you want your code to build on as broad a variety of different Unix systems then you're probably wise looking into GNU autoconf and automake . 如果你希望你的代码可以在各种不同的Unix系统上构建,那么你可能很明智地研究GNU autoconfautomake These help you construct a configure script and makefile for your project so that it will build on practically any Unix system. 这些可以帮助您为项目构建configure脚本和makefile ,以便它几乎可以在任何Unix系统上构建。

Also look into pkg-config which is used quite a bit now on Linux distributions for helping you include and link to the right libraries (for libs that support pkg-config). 另请参阅pkg-config ,它现在在Linux发行版上使用了很多,以帮助您包含和链接到正确的库(对于支持pkg-config的库)。

If you're using subversion to manage your source there is a "convention" that most subversion repositories use to manage their own code and "vendor" code. 如果您使用subversion来管理源代码,那么大多数subversion存储库都会使用“约定”来管理自己的代码和“供应商”代码。

Most svn repositories have a "vendor" tree (that goes along with the trunk, branches & tags trees). 大多数svn存储库都有一个“供应商”树(与树干,分支和标签树一起)。 That is the top for all 3rd party vendor code. 这是所有第三方供应商代码的首选。 In that directory you have directories for each library you use. 在该目录中,您可以使用每个库的目录。 Eg: 例如:

branches/
tags/
trunk/
vendor/somelib
vendor/anotherlib

Beneath each of these libs is a directory for each library version and a "current" directory for the most up-to-date version in your repository. 每个库下面都是每个库版本的目录,以及存储库中最新版本的“当前”目录。

vendor/somelib/1.0
vendor/somelib/1.1
vendor/somelib/current

Then your project's tree should be laid out something like this: 然后你的项目的树应该这样布局:

trunk/source # all your code in here trunk/libs # all vendor code in here trunk / source#这里的所有代码trunk / libs#所有供应商代码都在这里

The libs directory should be empty but it will have svn:externals meta data associated with it, via: libs目录应为空,但它将具有与之关联的svn:externals元数据,通过:

svn propedit svn:externals trunk/libs

The contents of this property would be something along the lines of (assumes subversion 1.5): 这个属性的内容将是(假设颠覆1.5):

^/vendor/somelib/current   somelib
^/vendor/anotherlib/1.0    anotherlib

This means that when you checkout your code subversion also checks out your vendor libraries into your trunk/libs directory. 这意味着当您签出代码时,subversion还会将您的供应商库检出到您的trunk / libs目录中。 So that when checked out it looks like this: 所以当签出时它看起来像这样:

trunk/source
trunk/libs/somelib
trunk/libs/anotherlib

This is described (probably a whole lot better) in the Subversion Book . Subversion Book中对此进行了描述(可能要好得多)。 Particularly the section on handling vendor branches and externals . 特别是关于处理供应商分支外部的部分

Ubuntu = Debian = apt-get goodness Ubuntu = Debian = apt-get goodness

Start with Linux Utilities : Linux实用程序开始:

%> sudo apt-get install util-linux

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

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