using libcurl without dll

Iron picture Iron · Aug 5, 2010 · Viewed 12.5k times · Source

I am using Microsoft Visual C++ 2010, and I need to make an application that does not require the libcurl dll. I am defining CURL_STATICLIB in the preprocessor directives and linking to libcurl.lib, libcurl_static.lib, ws2_32.lib, and winmm.lib, but it still requires the dll to work. If I only link to libcurl_static.lib, it has undefined external symbol errors. How can I get it working?

I have also tried building the source but I get 13 errors (wow, unlucky number) that all say "error C2011: 'pollfd' : 'struct' type redefinition". Could someone help me get libcurl working?

Answer

Andrey picture Andrey · Aug 6, 2010

There is no simple answer :) Libcurl depends on other third party libs (it depends on binary distribution that you are using). As you get rid of DLL - you'll have to link with corresponding third parties manually.

Ok, so the first point is that you should not link to libcurl.lib as it binds you to DLL which you don't want to.

Second point - when you are linking with libcurl_static.lib then (as mentioned above) you'll have also to link with libraries it depends on. Simple way to do that is to do something like this:

#if defined CURL_STATICLIB

#if defined _DEBUG
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\lib\\Debug\\curllib_static.lib")
#else
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\lib\\Release\\curllib_static.lib")
#endif

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\libeay32.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\openldap.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\ssleay32.lib")

#endif

But this way - you'll get three more dependencies. Alternatively, you can search for a way to link with them statically, but it is a different story.

As another alternative - you could rebuild libcurl_static.lib from sources after disabling all the features you don't need thus removing unwanted dependencies (as described in "Disabling Specific Protocols in Win32 builds" of INSTALL file).

And final point - as libcurl has quite poor support for windows compilation from sources, I'd recommend you to revisit the idea of getting rid of curllib.dll.