简体   繁体   English

在 Visual Studio 中链接多个库 C++

[英]Linking multiple libraries in Visual Studio C++

I am building a library to act as an AWS wrapper (lets call it awswrp.lib ).我正在构建一个库来充当 AWS 包装器(我们称之为awswrp.lib )。 When I want to use it in an external project, I include the header and reference the lib file.当我想在外部项目中使用它时,我包含 header 并引用 lib 文件。 However, it ask me to include all the headers and libs that are already included all the AWS libs that are already included in awswrp.lib .但是,它要求我包括所有已经包含的标头和库,所有已经包含在awswrp.lib中的 AWS 库。

As far as I understood linking, once you link the top most library you didn't need to link the rest of the libraries.据我了解链接,一旦你链接了最顶层的库,你就不需要链接库的 rest 了。 But now I am doubting this.但现在我对此表示怀疑。

Am I missing something?我错过了什么吗?

Appreciate any help感谢任何帮助

It sounds like you are confusing the older system of headers/libraries, and the newer system of modules.听起来你在混淆旧的头文件/库系统和新的模块系统。 Modules contain all the information for linking and would solve your problem.模块包含所有链接信息,可以解决您的问题。 Visual Studio does support modules, so it's something you might consider using. Visual Studio 确实支持模块,因此您可能会考虑使用它。 See here for how . 看这里如何 However, module support in visual studio is not perfect.然而,visual studio 中的模块支持并不完美。

To solve your issue in a more traditional manner, you must understand that each project has it's own settings.要以更传统的方式解决您的问题,您必须了解每个项目都有自己的设置。 In visual studio you can share settings between projects, but is is not done by default.在 visual studio 中,您可以在项目之间共享设置,但默认情况下不会这样做。 You can place the settings for using your libarary inside a file called a property (or prop) file.您可以将使用库的设置放在称为属性(或 prop)文件的文件中。 This sets the locations of the header directories and the required libraries for building, and even things like compiler flags.这设置了 header 目录的位置和构建所需的库,甚至是编译器标志之类的东西。 It is traditional to then make a single header file that includes all the others, which makes it easier to maintain.传统做法是制作一个包含所有其他文件的 header 文件,这样更易于维护。 In every project that uses your library, include the "props" file.在每个使用你的库的项目中,包含“props”文件。 The GUI for managing the properties is called the "property manager" and is hard to find, but it is the easiest way to do this.用于管理属性的 GUI 称为“属性管理器”,很难找到,但这是最简单的方法。

Be aware, that you still need to solve your issues one at a time.请注意,您仍然需要一次解决一个问题。 To fix missing header files add new directories to the prop file, and include your single-include-file to every module that requires it.要修复丢失的 header 文件,请将新目录添加到 prop 文件,并将您的单一包含文件包含到每个需要它的模块中。

If it then fails to link, add any library requirements.如果它随后无法链接,请添加任何库要求。 If it fails to find the libraries (different error), then use the separate directory setting for libraries to add those locations.如果找不到库(不同的错误),则使用库的单独目录设置来添加这些位置。

When making a prop-file, it is important to decide whether you need relative or absolute directory names.制作 prop 文件时,重要的是要决定您需要相对目录名还是绝对目录名。 If you share the code with other people, you must design a directory layout that is relative to some known directory.如果与其他人共享代码,则必须设计一个相对于某个已知目录的目录布局。

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

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