简体   繁体   English

如何将第三方库无缝集成到Visual Studio 2017中?

[英]How do you seamlessly integrate a third party library into Visual Studio 2017?

I want to take libFoobar/lib and libFoobar/include and tell VS2017 to make compiling and linking with them work by default for all projects. 我想把libFoobar / lib和libFoobar / include告诉VS2017进行编译和链接, 默认情况下所有项目都有效。

In earlier versions there was a global setting for compiler directories but I believe they deprecated that and made it completely project level. 在早期版本中,有一个编译器目录的全局设置,但我相信他们已经弃用了它并使其完全是项目级别的。

You can manually add a third party library to a project by configuring its project settings Under C/C++ / additional include directories and linker / input / additional dependencies. 您可以通过在C / C ++ /其他包含目录和链接器/输入/其他依赖项下配置其项目设置,手动将第三方库添加到项目中。

I don't want to have to store or memorize the names and locations of all of the .lib files or /include directories that I might need and manually re-enter them every time I start a new project or have to recreate an existing project. 我不想存储或记住我可能需要的所有.lib文件或/ include目录的名称和位置,并且每次启动新项目时都必须手动重新输入它们,或者必须重新创建现有项目。

There may be a way to create and maintain a project template which would be a solution. 可能有一种方法可以创建和维护项目模板 ,这将是一种解决方案。

You can add .libs to the project from the source code via #pragma comment(lib, "libFoobar.lib"). 您可以通过#pragma comment(lib,“libFoobar.lib”)从源代码中将.libs添加到项目中。 The most convenient overall method that I've got so far is to add /libFoobar/lib to the PATH variable, add the libs via #pragma to each header file, and manually add the /include directory to each project. 到目前为止,我最方便的整体方法是将/ libFoobar / lib添加到PATH变量,通过#pragma将libs添加到每个头文件,并手动将/ include目录添加到每个项目。 But that's a hack. 但这是一个黑客。

I did try to use "INCLUDE" and "LIBPATH" environment variables but they did not exist and adding them did nothing: 我确实尝试使用“INCLUDE”和“LIBPATH”环境变量但它们不存在并且添加它们什么也没做:

https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=vs-2019 https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=vs-2019

They might be valid on 2019 only. 它们可能仅在2019年有效。

Yes, project templates are a thing, and should accomplish this. 是的,项目模板是一个东西,应该做到这一点。

Here's some documentation I found by Googling "VS project templates": 这是我通过Google搜索“VS项目模板”找到的一些文档:

Instead of making project templates you can modify the default project property sheets. 您可以修改默认项目属性表,而不是制作项目模板。

Go to View->Other window->Property manager then open one of the nodes for the machine type you are working with (debug and release builds share the actual property sheet file). 转到视图 - >其他窗口 - >属性管理器,然后打开您正在使用的机器类型的一个节点(调试和发布版本共享实际的属性表文件)。 Right click on Microsoft.Cpp..user and select Properties, you can then make changes just like any other property sheet and the settings will be picked up by projects generated using the default wizards. 右键单击Microsoft.Cpp..user并选择Properties,然后可以像任何其他属性表一样进行更改,并且使用默认向导生成的项目将获取设置。

This is the replacement system for the mentioned prior global setting. 这是上述先前全局设置的替换系统。

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

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