Hello everyone, I tried for weeks to get the static libcurl to build correctly with MSVC and had all kinds of errors. While there is lots of good information, it is generally very limited to MSVC. I created a step by step process for how to compile a static lib using MSVC. Hopefully this will help anyone else who is struggling. Note: At this stage you still are required to have the SSL .dll files. I don't have those static libs (if anyone has them, or has a guide on how to get/create them please let me know).
For testing purposes. I have created a new C++ Win32 console application. I'd like to do a very basic test of adding the static lib and compiling it. Basically creating an exe file that does not require the libcurl dll. Created a folder: D:\VS2010\CustomLibs\cURLLibs Inside of there I unzipped ( http://curl.haxx.se/latest.cgi?curl=win32-ssl-devel-msvc ) Few examples of the folder structure: D:\VS2010\CustomLibs\cURLLibs\include\curl (has a bunch of the .h files in it) D:\VS2010\CustomLibs\cURLLibs\lib\Release (has curllib.lib, curllib.dll, curllib_static.lib) This is my starting app in c++. #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } I add #pragma comment(lib, "curllib_static.lib") I change the active output to Released. I add D:\VS2010\CustomLibs\cURLLibs\lib\Release to VC++ directories -> Libs At this stage, I do a "Build" simply to ensure it is able to find it - it builds successfully (does nothing!). In solution explorer I add a new filter: curl files I then add all the .h files. I add #include "curl/curl.h" I add D:\VS2010\CustomLibs\cURLLibs\include to VC++ directories -> Include I do a "Build" simply to ensure still no errors before I continue - it builds successfully (does nothing!). My output file is 6kb, so already I know I'm missing something because it's not including the curllib_static into the exe. But none the less, I shall continue on and maybe the error of my ways will present itself. I add D:\VS2010\CustomLibs\cURLLibs\lib\Release\curllib_static.lib to my filter curl files. Using this file: D:\VS2010\CustomLibs\cURLLibs\docs\examples\https.c as a basis, I start adding to see if I can get it to work. This is what I have now. #include "stdafx.h" #pragma comment(lib, "curllib_static.lib") #include "curl/curl.h" int _tmain(int argc, _TCHAR* argv[]) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/"); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } return 0; } Which gives me errors: Error 3 error LNK2001: unresolved external symbol __imp__curl_easy_cleanup D:\VS2010\curltest\curltest\curltest.obj curltest etc etc. However, I KNOW I have seen these many times while searching for help. http://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur Okay, since I am wanting to use the static lib, and I am using Visual studio, I'll follow this.. When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section. I go to properities -> C++ -> Preprocessor -> Preprocessor Definitions and add in CURL_STATICLIB That fixes those. Then I get.. Error 178 error LNK2001: unresolved external symbol __imp__acc...@12 D:\VS2010\curltest\curltest\curllib_static.lib(ftp.obj) curltest (lots of those types). I end up here: http://curl.haxx.se/mail/lib-2007-11/0300.html So I add.. #pragma comment(lib, "wldap32.lib") #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "winmm.lib") Now I end up with errors like: Error 101 error LNK2001: unresolved external symbol _ASN1_INTEGER_get D:\VS2010\curltest\curltest\curllib_static.lib(ssluse.obj) curltest I google that and also notice the ssluse.obj - So this seems to be related to ssl. I see 3 more libs in the directory.. I add them: #pragma comment(lib, "ssleay32.lib") #pragma comment(lib, "openldap.lib") #pragma comment(lib, "libeay32.lib") I add D:\VS2010\CustomLibs\cURLLibs to VC++ directories -> Libs Quick summary: #include "stdafx.h" #pragma comment(lib, "curllib_static.lib") #pragma comment(lib, "wldap32.lib") #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "winmm.lib") #pragma comment(lib, "ssleay32.lib") #pragma comment(lib, "openldap.lib") #pragma comment(lib, "libeay32.lib") #include "curl/curl.h" int _tmain(int argc, _TCHAR* argv[]) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/"); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } return 0; } Build succeeded!
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
