C++ 何时使用 Visual Studio 附加依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4066405/
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
When to use the Visual Studio Additional dependencies?
提问by user205834
In C++, you got the header files (.h), the (.lib) files and the (.dll) files.
在 C++ 中,您获得了头文件 (.h)、(.lib) 文件和 (.dll) 文件。
In Visual Studio, you provide the location to search for these files in three different places:
在 Visual Studio 中,您提供在三个不同位置搜索这些文件的位置:
Configuration Properties => C/C++ => General => Additional Include directories. Here you list out the "include" directories that you want searched and made available.
Configuration Properties => Linker => General => Additional Library directories. Here you list out the "lib" directories that you want to be searched and made available.
Configuration Properties => Linker => Input => Additional dependencies. Here you explicitly specify the .lib files that want to include.
配置属性 => C/C++ => 常规 => 其他包含目录。在这里您列出了您想要搜索并使其可用的“包含”目录。
配置属性 => 链接器 => 常规 => 附加库目录。在这里,您列出了要搜索并使其可用的“lib”目录。
配置属性 => 链接器 => 输入 => 附加依赖项。在这里,您明确指定要包含的 .lib 文件。
The questions are:
问题是:
Q1: If you have specified the header file in #1 and the lib in #2, why/when would you want to specify anything in #3?
Q1:如果您在#1 中指定了头文件,在#2 中指定了lib,为什么/何时要在#3 中指定任何内容?
Q2: I see people including a specific debug or release version of a lib in #3. Can you specify either the debug or the release version of a lib in #3 and still build in release or debug mode? Ideally, which version of the library debug/release should be provided here?
Q2:我看到有人在#3 中包含了一个特定的调试或发布版本的库。您能否在 #3 中指定 lib 的调试版本或发布版本,并且仍然在发布或调试模式下构建?理想情况下,这里应该提供哪个版本的库调试/发布?
回答by Jerry Coffin
- Configuration Properties => C/C++ => General => Additional Include directories. Here you list out the "include" directories that you want searched and made available.
- 配置属性 => C/C++ => 常规 => 其他包含目录。在这里您列出了您想要搜索并使其可用的“包含”目录。
This tells the compiler where to look for header files enclosed in angle brackets. This affects how the compiler (or preprocessor) does it's job.
这告诉编译器在哪里查找尖括号中的头文件。这会影响编译器(或预处理器)的工作方式。
- Configuration Properties => Linker => General => Additional Library directories. Here you list out the "lib" directories that you want to be searched and made available.
- 配置属性 => 链接器 => 常规 => 附加库目录。在这里,您列出了要搜索并使其可用的“lib”目录。
This tells the linker where to look for libraries (i.e., what directories to look in). This affects how the linker (rather than the compiler) does its job.
这告诉链接器在哪里查找库(即,要查找的目录)。这会影响链接器(而不是编译器)的工作方式。
- Configuration Properties => Linker => Input => Additional dependencies. Here you explicitly specify the .lib files that want to include.
- 配置属性 => 链接器 => 输入 => 附加依赖项。在这里,您明确指定要包含的 .lib 文件。
This tells the linker what libraries to look for in those directories. This also affects how the linker does its job.
这告诉链接器要在这些目录中查找哪些库。这也会影响链接器的工作方式。
Q1: Generally if you use 2, you almost certainly need to use 3 as well. 3 tells it what library to link with, and 2 tells it where to find that library. Of course, it can be more than one library as well.
Q1:一般如果你用2,你几乎肯定也需要用3。3 告诉它要链接哪个库,2 告诉它在哪里可以找到该库。当然,它也可以是多个库。
Q2: If a debug and release library are both provided, you typicallywant to use the debug version in a debug build and the release version in the release build. At the top-left corner of the dialog you select which configuration you want to modify. Typically you'll want to specify directories for both debug and release, but specify individual libraries, one for debug and one for release.
Q2:如果同时提供了调试和发布库,您通常希望在调试版本中使用调试版本,在发布版本中使用发布版本。在对话框的左上角,您可以选择要修改的配置。通常,您需要为调试和发布指定目录,但要指定单个库,一个用于调试,一个用于发布。
回答by Claude
And just to point out the obvious, you don't have to add any .h files you are using in a properties setting of your project because you explicitly include them in your source code, which looks for the headers in the paths you have already provided.
只是为了指出明显的一点,您不必在项目的属性设置中添加任何正在使用的 .h 文件,因为您明确地将它们包含在源代码中,它会在您已经拥有的路径中查找标头假如。
回答by Mark
Also, in those above places, when you add in a directory, look at the MACROS>> button. e.g. you may want to use different libraries for 32bit/64bit/Release and Debug. You can use the ($ProjectDir) MACRO to give a relative link, and e.g. the ($DXSDK_DIR) MACRO to make sure you get the right libs for your directx development.
此外,在上述那些地方,当您添加目录时,请查看 MACROS>> 按钮。例如,您可能希望对 32 位/64 位/发布和调试使用不同的库。您可以使用 ($ProjectDir) MACRO 来提供相对链接,例如 ($DXSDK_DIR) MACRO 以确保您获得用于 Directx 开发的正确库。
So I have ($DXSDK_DIR)\Lib\x86 and ($DXSDK_DIR)\Lib\x64 which also takes the problem away when moving between 32bit and 64bit Windows OS for development.
所以我有 ($DXSDK_DIR)\Lib\x86 和 ($DXSDK_DIR)\Lib\x64 这也解决了在 32 位和 64 位 Windows 操作系统之间移动进行开发时的问题。
回答by JasDev
Regarding your Q2...
关于您的第二季度...
For 3rd-party libraries, I take advantage of Visual Studio Build Command macro variables $(Platform)
and $(Configuration)
enter something like this:
对于 3rd 方库,我利用 Visual Studio Build Command 宏变量$(Platform)
并$(Configuration)
输入如下内容:
Y:\dev3\cpp\cryptopp\cryptopp561$(Platform)\Output$(Configuration);...
In this way, you can just enter the same exact line and Visual Studio substitute the macro variables and look in either \cryptopp561\Win32\Output\Release\
or \cryptopp561\Win32\Output\Debug\
depending on which configuration you have active. It doesn't actually save much typing but it helps keep things consistent and accurate.
通过这种方式,您只需输入完全相同的行,Visual Studio 将替换宏变量,然后根据您的活动配置查看\cryptopp561\Win32\Output\Release\
或查看\cryptopp561\Win32\Output\Debug\
。它实际上并没有节省多少打字,但它有助于保持一致和准确。