简体   繁体   English

如何手动将库添加到Visual Studio 2017项目?

[英]How to manually add a library to a visual studio 2017 project?

My apologies for this very basic question that has assuredly been asked and answered before, also for my very dated terminology. 我对这个非常基本的问题表示道歉,这个问题之前已经得到了肯定的回答,也是我过时的术语。 I searched for an answer, but failed to find anything helpful. 我搜索了一个答案,但未找到任何有用的信息。 I am using the latest update of VS 2017 Community, and I'm trying to manually add what I used to call a "function library" to a project, which sits under a "solution". 我正在使用VS 2017社区的最新更新,我正在尝试手动将我曾经称之为“函数库”的内容添加到项目中,该项目位于“解决方案”下。

The project is simply a C++ or C# console application. 该项目只是一个C ++或C#控制台应用程序。 What I have is a .h (header) file, a .lib (static library) file, and a .dll (dynamic library) file. 我所拥有的是.h(头文件)文件,.lib(静态库)文件和.dll(动态库)文件。 I intend to make "function calls" to this library. 我打算对这个库进行“函数调用”。 I'm aware that I need to have my dll in the debug folder where the executable resides, but I'm not sure how to "add dependencies" in VS 2017. I know how to manage and install NuGet packages, but these files aren't a handy-dandy NuGet package. 我知道我需要将dll放在可执行文件所在的调试文件夹中,但我不知道如何在VS 2017中“添加依赖项”。我知道如何管理和安装NuGet包,但这些文件不是这是一个方便的NuGet包。

I hope to get advice on doing this the right (VS 2017) way. 我希望得到关于这样做(VS 2017)方式的建议。

What I do in a situation like this is to create a folder, I use C:\\Etc\\SDKs\\<name_of_library> and then within that folder create an include subfolder, and a lib subfolder. 我在这种情况下做的是创建一个文件夹,我使用C:\\Etc\\SDKs\\<name_of_library>然后在该文件夹中创建一个include子文件夹和一个lib子文件夹。 Note that the top level folder choice is completely arbitrary, place it where it makes the most sense to you. 请注意,顶级文件夹选项完全是任意的,将其放在最适合您的位置。

In the C/C++ section of project properties on the General tab, or the corresponding section for C# projects, there's an entry for Additional include directories . 在“ General选项卡上的项目属性的C/C++部分或C#项目的相应部分中,有一个Additional include directories的条目。 Add the path to your newly created include folder there. 将路径添加到新创建的include文件夹。 That'll let you include the header file and have it work right. 这将允许您包含头文件并使其正常工作。

In the Linker section of project properties, also on its General tab, there's a corresponding entry for Additional library directories . 在项目属性的“ Linker部分中,也在其“ General选项卡上,有一个对应的Additional library directories条目。 Add the path to your lib folder there. 在那里添加lib文件夹的路径。 On the next tab down: Input there's an entry for Additional Dependencies . 在下一个选项卡上: Input有一个Additional Dependencies项的条目。 Add the actual name of the library file there. 在那里添加库文件的实际名称。

Those steps should allow your project to be built using the .h , .lib and .dll files you have. 这些步骤应该允许使用您拥有的.h.lib.dll文件构建项目。

-- Edit to address comments -- - 编辑以发表评论 -

The .lib file does go in the ...\\lib folder, and the .h file in the ...\\include , that's correct. .lib文件放在...\\lib文件夹中,而.h文件放在...\\include ,这是正确的。 However, you had the location of the .dll correct in your original question. 但是,您在原始问题中的.dll位置是正确的。 That needs to be somewhere on the search path that the executable will find, so the easiest place is the same folder as the executable. 这需要位于可执行文件将找到的搜索路径上的某个位置,因此最简单的位置是与可执行文件相同的文件夹。

General tab is a poor choice of words on my part. General选项卡对我来说是一个糟糕的选择。 General section might have been better here. General部分可能在这里更好。 When looking at the project properties, the left most pane is a tree view of the various property sections. 查看项目属性时,最左侧的窗格是各种属性部分的树视图。 With everything closed up, except the very top item open, you'll see 随着一切都关闭,除了最顶部的项目打开,你会看到

Configuration Properties
    General
    Debugging
    VC Directories
  > C/C++
  > Linker
    ...

If you then double click on C/C++ it'll open up, and show the sections specific to the C/C++ compiler: 如果然后双击C/C++它将打开,并显示特定于C / C ++编译器的部分:

Configuration Properties
    General
    Debugging
    VC Directories
  V C/C++
      General     <<<<<
      Optimization
      Preprocessor
      ...
  > Linker
    ...

If you click on the word `General that I've highlighted, that'll get you to the General section / tab I was talking about. 如果你单击“我已经突出显示的常规”这个词,那么你将进入我正在谈论的“常规”部分/标签。

Likewise, double clicking the word Linker will open up that section, and under that you'll find the Linker General and Input sections. 同样,双击文字Linker将开启一个部分,下,你会发现链接器GeneralInput部分。

Let me know if this still isn't clear, and I'll try to clarify. 如果这仍然不清楚,请告诉我,我会尽力澄清。

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

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