简体   繁体   English

将外部库包含到我自己的库项目 c++ visual studio

[英]Including an external library to my own library project c++ visual studio

Currently i have 3 visual studio projects:目前我有 3 个视觉工作室项目:

  • ConsoleApplication控制台应用程序
  • Logic逻辑
  • Test测试

These projects are all in the same solution.这些项目都在同一个解决方案中。 In the Logic project i use an external library named curl. My logic project is a static library made with the "new project" wizard in visual studio.在 Logic 项目中,我使用了一个名为 curl 的外部库。我的逻辑项目是一个 static 库,使用 Visual Studio 中的“新建项目”向导创建。 This project includes a pch.h file.该项目包含一个 pch.h 文件。 I added following things to my Logic project properties:我在我的逻辑项目属性中添加了以下内容:

  1. Set C/C++ > General > Additional Include Directories to the folder with the header files of curlC/C++ > General > Additional Include Directories设置为 curl 的 header 文件所在的文件夹
  2. Set Libarian > General > Additional Library Directories to the folder with curl.lib in it.Libarian > General > Additional Library Directories设置为包含 curl.lib 的文件夹。
  3. Set Libarian > General > Additional Dependencies to curl.lib.Libarian > General > Additional Dependencies设置为 curl.lib。

Now when i build the Logic project the output is a Logic.lib file.现在,当我构建 Logic 项目时,output 是一个 Logic.lib 文件。 i checked with DUMPBIN /SYMBOLS /EXPORTS Logic.lib if the Curl functions are actually in the lib file, and they are.我用 DUMPBIN /SYMBOLS /EXPORTS Logic.lib 检查了 Curl 函数是否确实在 lib 文件中,它们是。

To include the Logic project into the Console application i did the same 3 steps and added the Logic.lib to the Console application project.为了将 Logic 项目包含到控制台应用程序中,我执行了相同的 3 个步骤并将 Logic.lib 添加到控制台应用程序项目中。 Everything works fine untill the moment i start using classes that use the external curl library.一切正常,直到我开始使用使用外部 curl 库的类。 When i use these classes i get a link error: Unresolved external symbol (LNK 2019).当我使用这些类时,出现链接错误:未解析的外部符号 (LNK 2019)。 I have tried much to fix this, but it seems that i am not capable of solving it.我已经尝试了很多来解决这个问题,但似乎我无法解决它。 Am i doing something wrong that causes this not to work?我做错了什么导致这不起作用吗?

Also i would like to be able to use my logic project the same way as i do in my ConsoleApplication in my test project.此外,我希望能够像在我的测试项目中的 ConsoleApplication 中一样使用我的逻辑项目。 For more context why i splitted up those projects can be found in my previous question Use c++ classes from console application class in other project visual studio有关我拆分这些项目的更多背景信息,请参见我之前的问题Use c++ classes from console application class in other project visual studio

So after hours of research i found this post and i think this also applies to my case: Linking static libraries to other static libraries所以经过几个小时的研究,我发现了这篇文章,我认为这也适用于我的情况: Linking static libraries to other static libraries

TL;DR static libraries do not link with other static libraries TL;DR static 库不与其他 static 库链接

So i think the best solution in my case is to convert the static logic library to a dynamic lib (DLL)所以我认为对我而言最好的解决方案是将 static 逻辑库转换为动态库 (DLL)

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

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