0

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

Stan
  • 629
  • 7
  • 18
  • I expect you somehow messed up the settings and didn't properly link to curl.lib in the project that you see errors. Make sure you add the settings for all configurations. – drescherjm Oct 26 '20 at 15:39
  • Yes i pointed to the correct lib file for all the four configurations even for x64 or x86. And when i run my console application in debug or release in x86 or x64 it all generates the same error. I also tested the lib files in a console application without a library project and that just works – Stan Oct 26 '20 at 15:46
  • You added curl.lib for your console application? Adding logic.lib is not sufficient. – drescherjm Oct 26 '20 at 15:50
  • 1
    There is a setting that can make this work: [https://stackoverflow.com/a/61689250/487892](https://stackoverflow.com/a/61689250/487892) – drescherjm Oct 26 '20 at 15:56
  • I haved added curl.lib to my console application. It works when i call curl directly from console application. but when i use the class from my library that uses curl i get the same error. When i use both my class and directly use curl it suddenly works. But i get a warning (LNK4217) – Stan Oct 26 '20 at 16:41
  • Is Logic.lib a dll? I expected it was a static library. The `LNK4217` is about dlls – drescherjm Oct 26 '20 at 16:42
  • No in the configuration it says Static library (.lib) – Stan Oct 26 '20 at 16:43
  • The LNK4217 is about dllimport / dllexport which is confusing. You should not use that with a static lib – drescherjm Oct 26 '20 at 16:44
  • I assume curl is a dll and your are linking the import library for curl. – drescherjm Oct 26 '20 at 16:45
  • Maybe it's because i had to add several dlls to Additional dependecies because curl needed them: ws2_32.lib;wldap32.lib;advapi32.lib;kernel32.lib;comdlg32.lib;crypt32.lib;normaliz.lib; – Stan Oct 26 '20 at 16:46
  • No i have build the static library versions of curl. i followed this tutorial https://www.youtube.com/watch?v=q_mXVZ6VJs4&t=448s – Stan Oct 26 '20 at 16:49

1 Answers1

0

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)

Stan
  • 629
  • 7
  • 18
  • This used to be the case but I believe this answer fixes this: [https://stackoverflow.com/questions/61689155/how-to-combine-two-static-libraries/61689250#61689250](https://stackoverflow.com/questions/61689155/how-to-combine-two-static-libraries/61689250#61689250) however for my projects I have never tried this. I always specify all the libraries I need. – drescherjm Oct 27 '20 at 00:20
  • 1
    I tried to change that option in the property window of my Logic project but I still get the same error, maybe I have to try this with two static libraries that I created myself, because it might be a problem with the curl library specifically – Stan Oct 27 '20 at 09:39