简体   繁体   English

如何从Linux上的软件管理器链接到库?

[英]How do you link to a library from the software manager on Linux?

So I recently got fed up with Windows and installed Linux Mint. 所以我最近对Windows感到厌倦,并安装了Linux Mint。 I am trying to get a project to build I have in Code::Blocks. 我正在尝试建立我在Code :: Blocks中拥有的项目。 I have installed Code::Blocks but I need glew(as well as a few other libraries). 我已经安装了Code :: Blocks,但是我需要使用glew(以及其他一些库)。 I found it in the software manager and installed it. 我在软件管理器中找到并安装了它。 I've managed to locate and include the header files. 我设法找到并包含了头文件。 But I feel like the next step should be relatively straightforward and all over the internet but (perhaps due to lack of proper terminology) I have been as of yet unable to locate an answer. 但是我觉得下一步应该是相对简单的,并且应该遍及整个Internet,但是(也许由于缺乏适当的术语)我一直无法找到答案。

Do I need to locate the files on my system and link to each library manually? 我是否需要在系统上找到文件并手动链接到每个库? This is what I did on windows but I just downloaded the binaries and knew where they were. 这是我在Windows上执行的操作,但是我只是下载了二进制文件并知道它们的位置。 I found one library from the software manager and linked to it manually but it just feels like I'm doing it the wrong way. 我从软件管理器中找到了一个库,并手动链接了它,但感觉就像我做错了一样。 Since it's "installed" on the system is there some quick way to link? 由于它是“安装”在系统上的,因此有一些快速的链接方法吗?

You should use two flags for linker '-l' and '-L'. 您应该对链接器“ -l”和“ -L”使用两个标志。 You can set these flags somewhere in project properties. 您可以在项目属性中的某处设置这些标志。

The first one '-l' tells linker to link with particular library. 第一个“ -l”告诉链接器链接到特定的库。 For example glew, probably in /usr/lib is a file named libglew.so, when you link your program with '-lglew' flag, it will link it with glew library. 例如glew,可能在/ usr / lib中是一个名为libglew.so的文件,当您使用'-lglew'标志链接程序时,它将与glew库链接。 Linker looks for libraries in few standard places: /usr/lib, /usr/local/lib and few extra. 链接器在几个标准位置中查找库:/ usr / lib,/ usr / local / lib和其他一些地方。 If you have your libs in nonstandard place, use '-L' flag to point these dirs. 如果您的库位于非标准位置,请使用'-L'标志指向这些目录。

Many linux distributions provide two kinds of packages with libraries, regular ones just with runtime, and devel ones (usually prefixed or suffixed with dev or devel) with header files and development version of libraries. 许多Linux发行版提供两种带有库的软件包,常规的仅带运行时的软件包,以及带有头文件和库开发版本的devel软件包(通常带有dev或devel的前缀或后缀)。

use build systems, Luke! 使用构建系统,卢克! the typical way to develop/build software in *nix world is 3 steps: 在* nix world中开发/构建软件的典型方法是3个步骤:

  • configure stage -- before building smth you have to realize in what environment you are going to build your software... is everything that required is installed... it wouldn't be good if at compile stage (after few hours of compilation) you (or user who build your soft) got an error: unable to #include the 'xxx.h' . 配置阶段 -在构建smth之前,您必须意识到要在哪种环境中构建软件...是否已安装了所需的所有内容...如果在编译阶段 (经过几个小时的编译)就不好了您(或构建您软件的用户)遇到错误: 无法#include'xxx.h' the most popular build systems are: cmake , my favorite after autotools . 最受欢迎的构建系统是: cmake ,我最喜欢的自动工具 yout may try also scons or maybe crazy (b)jam... 您可能还会尝试scons或可能发疯(b)jam ...
  • compile stage -- usually just make all 编译阶段 -通常只是make所有
  • install stage -- deploy just built software into the system. 安装阶段 -将刚构建的软件部署到系统中。 or other way: build packages for target distro (.deb/.rpm/&etc) 或其他方式:构建目标发行版的软件包(.deb / .rpm /&etc)

at configuration stage using test scripts (don't worry there are plenty of them for various use cases) you can find all required headers/libraries/programs/compiler options/whatever you need to compile your package... and yes: do not use hardcoded paths in your Makefiles (or whatever you use to make your binaries) 在配置阶段使用测试脚本(不用担心会有很多用例用于各种用例),您可以找到所有必需的头文件/库/程序/编译器选项/无论您需要编译软件包的什么……是的: 不需要使用硬编码路径在Makefile中(或任何你用它来make你的二进制文件)

Answer to this question really depends on what you want to achieve. 对这个问题的答案实际上取决于您要实现的目标。 If you want just to build you app by yourself then you can just write path to libraries in your makefile, or your code editor settings. 如果您只想自己构建应用,则只需在makefile或代码编辑器设置中编写库的路径即可。 You may not even have to do that as if libraries installed by your linux distribution package manager, headers usually go to /usr/include and libraries to /usr/lib or /urs/lib64 etc. That locations are standard and you do not need to specify them explicitly. 您甚至不必这样做,就好像linux发行软件包管理器安装的库一样,标头通常转到/ usr / include,库通常转到/ usr / lib或/ urs / lib64等。该位置是标准位置,您不需要明确指定它们。 Anyway you need to specify libraries you want to link to. 无论如何,您都需要指定要链接的库。 If you want to create application that can be build by others, or by you on many different configurations/environments using something like cmake would be very helpful. 如果您要创建可以由其他人构建的应用程序,或者使用cmake之类的东西在许多不同的配置/环境上构建的应用程序,将非常有帮助。

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

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