windows 我应该把第三方库放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3605484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where should I put third-party libraries?
提问by Twisol
I contribute to a decent-sized C++ projectwith a number of dependencies. The problem is, the project contains the source of all of its dependencies (e.g. pcre, zlib, etc.). I want to trim the project down to just what's relevant to the program itself. Is there some relatively standard way to compile these libraries and put them somewhere, and have their header files also easily accessible?
我为一个具有许多依赖项的体面的 C++ 项目做出了贡献。问题是,该项目包含其所有依赖项的来源(例如 pcre、zlib 等)。我想将项目缩减为与程序本身相关的内容。是否有一些相对标准的方法来编译这些库并将它们放在某个地方,并且它们的头文件也很容易访问?
For what it's worth, I'm using Windows 7, and I'm developing using VS2005. I'm also a complete noob with working on large C++ projects on Windows; I've never really needed to step outside the standard library and win32.
就其价值而言,我使用的是 Windows 7,我正在使用 VS2005 进行开发。我也是一个在 Windows 上处理大型 C++ 项目的完全菜鸟;我从来没有真正需要走出标准库和 win32。
采纳答案by korbes
A structure that we use on my workplace is having one "External" folder that contains an "Include" and a "Lib" folder for the headers and external Libs. However, as we also use VS, we try to use its "Dependencies" feature as most as possible, removing manual inputs to the linker. That means only projects that are not under the same solution goes to the "External" folder. Also, as we have some third-party libraries specific to some projects, we create folders inside the project folder for these includes and libs. This is how it gets:
我们在我的工作场所使用的一种结构是有一个“外部”文件夹,其中包含一个“包含”和一个用于标题和外部 Lib 的“Lib”文件夹。但是,由于我们也使用 VS,因此我们尝试尽可能多地使用其“依赖项”功能,删除链接器的手动输入。这意味着只有不在同一解决方案下的项目才会进入“外部”文件夹。此外,由于我们有一些特定于某些项目的第三方库,我们在项目文件夹中为这些包含和库创建了文件夹。这是它的获取方式:
.\ |-Project1\ --> contains Project1.vcproj |-Project2\ --> contains Project2.vcproj | |-Third-Party\ | |-Include\ | |-Lib\ |-External\ | |-Include\ | |-Lib\ |-InternalLibrary\ --> contains InternalLibrary.vcproj |-Solution.sln --> includes the vcproj's and link them as necessary by its dependencies
I can't tell if this is the best structure ever, but everything is under source control, we can do night builds just by building the solution, and development goes by building single projects.
我不知道这是否是有史以来最好的结构,但一切都在源代码控制之下,我们可以通过构建解决方案来进行夜间构建,而开发则通过构建单个项目来进行。
回答by Andrew Shepherd
There's a fallacy in your statement: "I want to trim the project down to just what's relevant to the program itself."
你的陈述中有一个谬误:“我想把项目缩减到与项目本身相关的程度。”
Believe me, the dependencies are extremely relevant to the program. If you don't have these in source control then you will encounter no end of problems when introducing new team members or when switching to a new workstation.
相信我,依赖关系与程序极其相关。如果在源代码控制中没有这些,那么在引入新团队成员或切换到新工作站时,您将遇到无穷无尽的问题。
Even if compile the "non-relevant" libraries, these compiled libraries should go into your source repository.
即使编译“不相关”的库,这些编译的库也应该进入您的源存储库。
回答by Merlyn Morgan-Graham
I've seen groups do the following:
我见过团体执行以下操作:
- Separate internal code from external code (code they made vs external companies)
- Separate their code from library code
- Separate each program and each library
- Check in a compiled version of their dependencies, so it isn't a part of their full build cycle (at least, not in some branches. Other branches might do a more complete build)
- 将内部代码与外部代码分开(他们制作的代码与外部公司的代码)
- 将他们的代码与库代码分开
- 将每个程序和每个库分开
- 检查其依赖项的编译版本,因此它不是其完整构建周期的一部分(至少,不在某些分支中。其他分支可能会进行更完整的构建)
Projects existed for each exe or library, in the directory with the exe/library.
每个 exe 或库的项目都存在于 exe/library 目录中。
Solutions existed wherever the teams felt it would be beneficial, and binaries were often linked, rather than their projects included in the sub-solutions. Only a full build was guaranteed not to break on a fresh enlistment.
解决方案存在于团队认为有益的地方,并且二进制文件通常是相互关联的,而不是包含在子解决方案中的项目。只有完整的构建才能保证不会因新的入伍而中断。
Caveat emptor...
买者自负...