Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for using static version of libcurl (Visual Studio 14 2015) #196

Closed
no-realm opened this issue Mar 19, 2017 · 1 comment
Closed

Comments

@no-realm
Copy link

I have tried to use cpr with the static version of libcurl, but that doesn't seem to work, since libcurl_imp.lib isn't getting build for the static version of libcurl.
And since cpr links to libcurl_imp.lib, I am getting compile errors.

These are the errors:

1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_formadd referenced in function "public: void __cdecl cpr::Session::Impl::SetMultipart(class cpr::Multipart &&)" (?SetMultipart@Impl@Session@cpr@@QEAAX$$QEAVMultipart@3@@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_formfree referenced in function "public: void __cdecl cpr::Session::Impl::SetMultipart(class cpr::Multipart &&)" (?SetMultipart@Impl@Session@cpr@@QEAAX$$QEAVMultipart@3@@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_slist_append referenced in function "public: void __cdecl cpr::Session::Impl::SetHeader(class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct cpr::CaseInsensitiveCompare,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const &)" (?SetHeader@Impl@Session@cpr@@QEAAXAEBV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@UCaseInsensitiveCompare@cpr@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_slist_free_all referenced in function "private: class cpr::Response __cdecl cpr::Session::Impl::makeRequest(void *)" (?makeRequest@Impl@Session@cpr@@AEAA?AVResponse@3@PEAX@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_version_info referenced in function "public: __cdecl cpr::Session::Impl::Impl(void)" (??0Impl@Session@cpr@@QEAA@XZ)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function "private: static struct cpr::CurlHolder * __cdecl cpr::Session::Impl::newHolder(void)" (?newHolder@Impl@Session@cpr@@CAPEAUCurlHolder@3@XZ)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function "public: __cdecl cpr::Session::Impl::Impl(void)" (??0Impl@Session@cpr@@QEAA@XZ)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function "private: class cpr::Response __cdecl cpr::Session::Impl::makeRequest(void *)" (?makeRequest@Impl@Session@cpr@@AEAA?AVResponse@3@PEAX@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function "private: static void __cdecl cpr::Session::Impl::freeHolder(struct cpr::CurlHolder *)" (?freeHolder@Impl@Session@cpr@@CAXPEAUCurlHolder@3@@Z)
1>cpr.lib(session.obj) : error LNK2019: unresolved external symbol __imp_curl_easy_getinfo referenced in function "private: class cpr::Response __cdecl cpr::Session::Impl::makeRequest(void *)" (?makeRequest@Impl@Session@cpr@@AEAA?AVResponse@3@PEAX@Z)
@no-realm
Copy link
Author

Never mind.
Here are some things that you need to keep in mind.
Note that I don't know whether all steps are necessary for it to work, since I tried many different things.

Visual Studio

I am using Visual Studio 14 2015 Win64 for my project.

Runtime

You have to compile all static libraries with the same runtime!
In my case I used Multi-threaded (/MT) for my Release configuration and Multi-threaded Debug (/MTd) for my Debug configuration.

OpenSSL

If you want to use OpenSSL, you have to compile that too beforehand.
Here are some useful instructions for compiling OpenSSL: Build OpenSSL
You have to replace all instances of ntdll.mak with nt.mak, else you will get a dynamic library (dll).

After running nmake -f ms\nt.mak install, you will find all OpenSSL related files under \usr\local\ssl on the same drive.
That means, if you compiled OpenSSL on your E: drive, you will find the folder on the E: drive.

CPR & libcurl

Now coming to the main point.
Open your native command prompt. In my case VS2015 x64 Native Tools Command Prompt.
Now you need to set the OpenSSL environment variables (replace with the one you used):

set OPENSSL_ROOT_DIR=<drive letter>\usr\local\ssl
set OPENSSL_INCLUDE_DIR=<drive letter>\usr\local\ssl\include
set OPENSSL_LIB=<drive letter>\usr\local\ssl\lib

Move to the location where you want the cpr project the be located.
After cloning cpr, move into the cpr folder cd cpr and create a new folder build mkdir build.
Also move into the newly created build folder cd build.

Before using cmake, open the CMakeLists.txt file in cpr\opt\curl
and replace

option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)

with

option(CURL_STATICLIB "Set to ON to build libcurl with static linking." ON)

Now execute cmake: cmake -G "Visual Studio 14 2015 Win64" ..

You should now find a file named cpr.sln in the build folder.
Open it and modify the following values:

  • Change the runtimes (Debug/Release) in these three porjects to the ones you plan to use in your project: cpr, libcurl, mongoose
  • Add CURL_STATICLIB to Preprocessor Definitions for both Debug and Release (You have to do the same thing in your project).

Now you can right click the cpr project and build it.
The libraries can be found in cpr\build\lib\[Debug/Release].

Your Project

I would recommend creating a folder for all dependencies.
For example:

dependencies/
--> includes
      --> cpr/
--> libs
      --> Debug
      --> Release

Copy the respective libraries into the Debug/Release folder: cpr.lib, libcurl.lib, libeay32.lib, ssleay32.lib
You can find libeay32.lib and ssleay32.lib in \usr\local\ssl\lib.

For both Debug and Release:

  • Add $(SolutionDir)dependencies\includes to Additional Include Directories.
  • Add $(SolutionDir)dependencies\libs\$(Configuration) to Additional Library Directories.
  • Add cpr.lib libcurl.lib libeay32.lib ssleay32.lib ws2_32.lib Wldap32.lib to Additional Dependies.
  • Add CURL_STATICLIB to Preprocessor Definitions

This should do it. I might have forgot some things, so sorry.
I hope this helped.

@no-realm no-realm changed the title Option for using static version of libcurl Option for using static version of libcurl (Visual Studio 14 2015) Mar 19, 2017
@no-realm no-realm closed this as completed May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant