[英]How would I make sure that the needed headers required in my C++ program are installed on the user's machine?
I have a C++ project that uses the popular Boost library.我有一个使用流行的Boost库的 C++ 项目。 The problem is, if someone downloads my code off say, Github and tries to build it, it won't work unless they have Boost installed, which could be an inconvenience.
问题是,如果有人下载我的代码 Github 并尝试构建它,除非他们安装了 Boost,否则它将无法工作,这可能会带来不便。 I'm just wondering how I would go about making sure these headers are accessible for the user so they can build the app themselves.
我只是想知道我将如何确保用户可以访问这些标头,以便他们可以自己构建应用程序。 Would I have to copy them into a separate folder in the directory?
我是否必须将它们复制到目录中的单独文件夹中? Are there better solutions?
有更好的解决方案吗?
Thanks谢谢
There are quite a lot of options on how to manage dependencies.关于如何管理依赖项有很多选择。 In my experience many platforms define it's own conventional way of doing so.
根据我的经验,许多平台都定义了自己的传统方式。 Eg in iOS development people either use CocoaPods or SwiftPackages (and sometimes Carthage).
例如,在 iOS 开发人员使用 CocoaPods 或 SwiftPackages(有时还有 Carthage)。 For Android applications, developers usually define dependencies in
dependencies
block of their Gradle-build script (which essentially takes them from remote repos).对于 Android 应用程序,开发人员通常在 Gradle-build 脚本的
dependencies
项块中定义依赖项(本质上是从远程存储库获取它们)。
There isn't necessary an industry standard, but there is something other developer usually find consistent .没有必要的行业标准,但其他开发人员通常会发现一些一致的 .
As far as I'm concerned, in C++ world the dependencies are expected to be managed via CMake
.就我而言,在 C++ 世界中,依赖项预计将通过
CMake
进行管理。 I wouldn't say that CMake itself defines conventional way of managing dependencies (there is far more than one approach of doing so), but the part which everyone expects is that when your CMake script finishes successfully, it has all dependencies set up.我不会说 CMake 本身定义了管理依赖项的传统方式(这样做的方法远不止一种),但每个人都期望的部分是,当您的 CMake 脚本成功完成时,它已经设置了所有依赖项。 Here are a few options you have when managing dependencies via CMake:
在通过 CMake 管理依赖项时,您可以使用以下几个选项:
find_package
- the most widespread way. find_package
- 最普遍的方式。 As a result, this command should end up with include dirs and a library target configured in your cmake script (against which you link your own project).Find<Library_name>.cmake
files where you give instructions for CMake how to find the given library.Find<Library_name>.cmake
文件,您可以在其中提供有关 CMake 如何找到给定的图书馆。add_subdirectory
on those dependencies in you CMakeLists.txt
- my preferable way.CMakeLists.txt
中对这些依赖项使用add_subdirectory
- 我的首选方式。 First, I like it because it's highly portable, you don't expect the host machine to be configured in any specific way, second, it doesn't spread dependencies beyond the project directory. Thanks to flexibility of CMake, you also can add any intermediate steps to easy the installation of dependencies, including, but not limited to, automatic git submodules pull and update, or installing some missing tools.由于 CMake 的灵活性,您还可以添加任何中间步骤来轻松安装依赖项,包括但不限于自动 git 子模块拉取和更新,或安装一些缺少的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.