简体   繁体   English

C++ 如何管理依赖项(例如使用来自 github 的库)

[英]C++ how to manage dependencies (use libraries from github for example)

I'm very new to C++ world, so please, sorry me for such a dummy question.我对 C++ 世界很陌生,所以请原谅我提出这样一个愚蠢的问题。 I google a little, but wasn't able to find proper answer.我谷歌了一下,但无法找到正确的答案。

My question is fairly simple - how should I use lib's in C++ world.我的问题很简单 - 我应该如何在 C++ 世界中使用 lib。 For example in Java - there is maven and gradle for this task.例如在 Java 中 - 这个任务有mavengradle In Python - I use pip .在 Python 中 - 我使用pip In javascript npm and bower do all the stuff.在 javascript npmbower做所有的事情。 In C# you use nuget or just adding DLL lib to your project.在 C# 中,您可以使用nuget或只是将 DLL 库添加到您的项目中。 But looks like in C++ things isn't such easy.但是看起来在 C++ 中事情并不那么容易。

I found a tool, called conan but ammount of libs they have is pretty small and don't include any what i'm loking for.我找到了一个名为conan的工具,但是他们拥有的库数量非常少,并且不包含任何我想要的东西。

So, for example - I want to use nlp lib meta .所以,例如 - 我想使用 nlp lib meta Seem's like they don't provide any installer file.好像他们不提供任何安装程序文件。 So I assume I need to get sources from github.所以我假设我需要从 github 获取源代码。 Should I compile them and then trying to add compiled files to my project or I need to have lib folder in my project, and put meta's sources in those folder and after operate with meta's sources as they are in my project?我应该编译它们,然后尝试将编译的文件添加到我的项目中,还是我需要在我的项目中有lib文件夹,并将meta's源代码放在这些文件夹中,然后像它们在我的项目中一样使用meta's源代码进行操作?


My question isn't about how to install specific meta lib, but more from the source management point of view.我的问题不是关于如何安装特定的meta库,而是更多从源代码管理的角度来看。 If I use Visual Studio on Windows for example, but my colegue will be coding Clion under Linux .例如,如果我在Windows上使用Visual Studio ,但我的同事将在Linux下编码Clion And I wan't to realize which is a proper way to managing dependencies in C++ world.而且我不想意识到在 C++ 世界中管理依赖项的正确方法是什么。

C++ doesn't have anything like pip or npm/bower . C++ 没有像pipnpm/bower这样的东西。 I don't know if maven or gradle can be persuaded to handle C++ libraries.我不知道是否可以说服mavengradle来处理 C++ 库。

In general, you are going to have to end up with一般来说,你将不得不结束

  • Header files in a directory somewhere某个目录中的头文件
  • library files (either static libraries, or DLLs/shared objects).库文件(静态库或 DLL/共享对象)。 If the library is a header-only library like some of the boost libraries, then you won't need this.如果库是像某些 boost 库一样的仅头文件库,那么您将不需要它。

You get hold of the library files, either by building them on your machine (typical for open source projects, and projects aimed at Linux platforms), or by downloading the pre-compiled binaries (typical for Windows libraries, particularly paid-for).您可以通过在您的机器上构建它们来获取库文件(通常用于开源项目和针对 Linux 平台的项目),或者通过下载预编译的二进制文件(通常用于 Windows 库,特别是付费的)。

Hopefully, the instructions for building the library will be included on the library website.希望图书馆网站上将包含构建图书馆的说明。 As noted in the comments, 'meta' seems to be quite good at that.正如评论中所指出的,“元”似乎非常擅长。

When you try to compile with the library, you may need a command line option (eg -I ) to specify the directory containing the header files, and you may need a linker option (eg -l ) to tell the linker to link against your library.当您尝试使用库进行编译时,您可能需要一个命令行选项(例如-I )来指定包含头文件的目录,并且您可能需要一个链接器选项(例如-l )来告诉链接器根据您的图书馆。

Cget will install any package that uses standard cmake, and works for linux and windows. Cget将安装任何使用标准 cmake 的包,并且适用于 linux 和 windows。 It has shorten syntax for getting packages directly from github(such as cget install google/googletest ).它缩短了直接从 github 获取包的语法(例如cget install google/googletest )。

In addition, dependencies can be automatically downloaded as well by listing them in a requirements.txt file.此外,还可以通过在requirements.txt文件中列出依赖项来自动下载依赖项。

There is also recipes for installing non-cmake packages and the repository here has over 300 libraries(and growing).还有安装非 cmake 包的方法,这里的存储库有 300 多个库(并且还在增长)。 So you can install curl with just cget install pfultz2/cget-recipes curl .因此,您只需使用cget install pfultz2/cget-recipes curl

C++ sadly has no package manager for libraries.遗憾的是,C++ 没有库的包管理器。 Some are out there and try to be one which are still small and scattered though (like conan).有些人在那里并试图成为一个仍然小而分散的人(如柯南)。

In linux you have some "-dev" packages you can install but they are also not "all".在 linux 中,您可以安装一些“-dev”包,但它们也不是“全部”。

You most likely end up downloading them yourself.您很可能最终自己下载它们。 Next though is you have the problem of integrating those libraries.不过接下来是集成这些库的问题。 You have different build systems per operating system so you have to see how you build c++ files.每个操作系统都有不同的构建系统,因此您必须了解如何构建 C++ 文件。

Like in windows with Visual studio you have to get a visual studio project or a nmake compatible makefile to build the libraries and then add them to your project.就像在带有 Visual Studio 的 Windows 中一样,您必须获得一个 Visual Studio 项目或一个与 nmake 兼容的 makefile 来构建库,然后将它们添加到您的项目中。 Same with linux makefiles.与 linux makefile 相同。

There are several build frameworks who are higher level like cmake .有几个构建框架的级别更高,例如cmake The example you have in your post also works with CMake.您在帖子中的示例也适用于 CMake。 So integrating that one into a cmake build environment would be easier but this only applies for other libraries also trying to use/integrate cmake build environments to it (eg boost / qt is doing this).因此,将其集成到 cmake 构建环境中会更容易,但这仅适用于也尝试使用/集成 cmake 构建环境的其他库(例如 boost / qt 正在这样做)。

Yeah these are some thoughts to this.是的,这些是对此的一些想法。 Sadly there won't be an easy/definitive answer to this because there is no real central c++ packet repository which is also integrated into a build system.遗憾的是,对此不会有一个简单/明确的答案,因为没有真正的中央 C++ 数据包存储库也集成到构建系统中。

It appears to me that the Crascit/DownloadProject could be of help in your situation.在我看来Crascit/DownloadProject可能对您的情况有所帮助。 It provides CMake plugins for downloading projects from a git repository by specifying tags , etc. Then you can use add_custom_target to run commands you need to have the project built.它提供了CMake插件,用于通过指定tags等从 git 存储库下载项目。然后您可以使用add_custom_target运行您需要构建项目的命令。

There are a number of popular C++ released via nuget packages .有许多流行的 C++ 通过nuget 包发布。 You can search on the gallery for them, usually using the native or c++ tags.您可以在图库中搜索它们,通常使用本nativec++标签。 Obviously you need a nuget manager for your OS, and I'm pretty sure that the C++ nuget packages rely on MSBuild for a lot of the grunt work, so you may have trouble getting a non-Visual Studio oriented setup to work nicely.显然,您的操作系统需要一个 nuget 管理器,而且我很确定 C++ nuget 包依赖 MSBuild 来完成许多繁重的工作,因此您可能无法让非面向 Visual Studio 的设置正常工作。

Also Gradle actually does have some support for native dependencies as well.此外,Gradle 实际上也对 本机依赖项提供了一些支持。 I had a look at little while ago but the work on it was curtailed because the support for VS 2015 was lacking.不久前我看了看,但由于缺乏对 VS 2015 的支持,因此减少了对它的工作。

I recommend vcpkg for cross platform development.我推荐vcpkg用于跨平台开发。 It has a number of IDE integrations.它有许多 IDE 集成。 GitHub project is here . GitHub 项目在这里

I do cross platform development using tools like CMake, Visual Studio, WSL.我使用 CMake、Visual Studio、WSL 等工具进行跨平台开发。 vcpkg was incredibly helpful. vcpkg 非常有帮助。

I started new project... in cureent time it's just "source package manager" you can provide some source code on github and then it will be just copy to you project (based on cmake + auto generating cmake files)我开始了新项目......在当前它只是“源包管理器”,你可以在github上提供一些源代码,然后它就会被复制到你的项目中(基于cmake +自动生成cmake文件)

So links here: https://github.com/wsjcpp/wsjcpp所以链接在这里: https : //github.com/wsjcpp/wsjcpp

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

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