3
votes

So I've been trying to statically link the libcurl library to my project for the past DAY and I'm literally pulling my hair out. Everywhere on the internet different instructions are given and none seem to work. I've never statically liked a library before but now I have to (for the sake of keeping things organized).

So my project is a .dll file, which requires the libcurl library to function. I've managed to build a libcurl.lib file from the libcurl source, but I have no idea what I need to do with the properties of my dll project. I've tried adding it to "Additional library directories", "Additional include directories", "Additional dependencies" all without success. Some configurations seem to work, but in the end it still doesn't link statically, only dynamically. Oh, and I'm using Visual Studio 2013.

Does anyone have any experience statically linking libcurl? Any help would be much appreciated. Thanks!

1
"Additional dependencies" is the way to go. If you say your DLL still depends on libcurl DLL after that, then the .lib file you have is an import library for the latter DLL after all, not a static library.Igor Tandetnik
Project > Properties > C/C++ > General > Additional Include Directories. List a directory there that's the parent of a directory named curl, which in turn contains a file named curl.h.Igor Tandetnik
Is the problem that libcurl.dll can't be found, or that it's required at all? I thought it was the latter, but your last comment makes it sound like the former. If it's "not found" what bothers you, copy libcurl.dll to the same directory where your EXE is (usually, ProjectName\Debug or ProjectName\Release).Igor Tandetnik
There are two types of files, both unfortunately having .lib extension. A static library contains actual code; when linked, that code physically becomes part of the executable (EXE or DLL) it's linked with. An import library doesn't contain any code, just references to functions exported from a companion DLL; when linked, the executable takes a dependency on said DLL. As far as I can tell, libcurl.lib you have is of this latter variety - an import lib.Igor Tandetnik
That is in fact how you build a static library. Make sure you are linking to the correct .lib file - chances are, when you've downloaded pre-built libcurl.dll, it came together with libcurl.lib import library, and perhaps that's the one the linker is picking up. How to tell them apart: a static library is typically large, about the same size as the DLL or even larger, while import library is a fraction of the size. If you do in fact have two of them, try renaming the smaller one, to make sure you aren't inadvertently linking with it.Igor Tandetnik

1 Answers

2
votes

After a lot of experimenting I finally figured it out: I had to do exactly this (for anyone else experiencing these issues):

  1. Open properties
  2. Go to Configuration Properties -> VC++ Directories
    1. Add the location of your curldownload/lib folder to "Library Directories"
  3. Go to Configuration Properties -> C/C++ -> General
    1. Add the location of your curldownload/include folder to "Additional Include Directories"
  4. Go to Configuration Properties -> Linker -> Input
    1. Add this to "Additional Dependencies": libcurl.lib;ws2_32.lib;wldap32.lib;advapi32.lib;kernel32.lib;comdlg32.lib
    2. Add "libcmt.lib" to "Ignore Specific Default Libraries"

And then it compiled. Hope that helped!