Search code examples
c++visual-studiolinkerdependenciesstatic-libraries

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


Currently i have 3 visual studio projects:

  • 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. This project includes a pch.h file. 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 curl
  2. Set Libarian > General > Additional Library Directories to the folder with curl.lib in it.
  3. Set Libarian > General > Additional Dependencies to curl.lib.

Now when i build the Logic project the output is a Logic.lib file. i checked with DUMPBIN /SYMBOLS /EXPORTS Logic.lib if the Curl functions are actually in the lib file, and they are.

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. Everything works fine untill the moment i start using classes that use the external curl library. When i use these classes i get a link error: Unresolved external symbol (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. 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


Solution

  • 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

    TL;DR static libraries do not link with other static libraries

    So i think the best solution in my case is to convert the static logic library to a dynamic lib (DLL)