Creating a static library for Casablanca C++ rest SDK 2.3

Jan 29, 2015 at 8:59 AM
I am trying to create a static library for my C++ rest SDK project.I have installed Casablanca C++ rest SDK 2.3 using Nuget package. My OS is Winodws8 and I am using VS2012.I have added the cpprest110d_2_3.lib into "Project Property --> Linker --> Input -->Additional Dependencies" and the includes in the Additional Include Directories .

Howerver I am getting the following link errors

error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::GET" (?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)

error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::POST" (?POST@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)

error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::PUT" (?PUT@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)

error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::DEL" (?DEL@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)

I have also tried replacing the lib file with cpprest110d_app_2_3.lib file but I am getting the same errors.

I have directly used the lib files available from the packages that I downloaded from Nuget package.

Please help me in resolving this issue and also time is running out for my project
Jan 29, 2015 at 6:46 PM
Hi roshan,

The C++ REST SDK does not currently support building as a static library. If you add the NuGet package to your project, it will automatically select the correct .lib and .dll to link against your binary.

roschuma
Jan 29, 2015 at 8:32 PM
roshan,

If you really want static linking others have had success building from the source themselves. See here.

Steve
Jan 30, 2015 at 5:04 AM
Thank you guys for the reply.

My scenario is I have built a static library project which uses C++ REST SDK.I was successfully able to generate the lib file for my project but when I try to use this lib file in other C++ application,I am getting those linker errors.

Stevegates, I have already gone through that link and followed those steps with no luck.
Jan 30, 2015 at 6:48 PM
Are you linking the C++ REST SDK against your other C++ application? Try adding the NuGet package to that application as well.
Feb 2, 2015 at 3:36 AM
I understand that adding NuGet package to the application will help my cause but I cannot expect every C++ application to install C++ rest SDK through NuGet package.Is there any alternative way to link ?also how to find out which lib(installed from Nuget package) is my C++ application using? and thanks roschuma for you replies.I really appreciate it.
Feb 2, 2015 at 9:26 PM
Ok, so I think I'm not understanding what your use case is here.
  • If you're making a library, (such as a DLL or a static lib), other programs which use your library will need to install the C++ REST SDK NuGet package to use your library. They will need to also follow the guidance below for applications.
  • If you're making an application, then you don't need to worry about other C++ applications. You just make sure to copy the cpprest120_2_4.dll file along with your ConsoleApplication1.exe and everything will work fine.
Basically, yes, you can expect every C++ application which wants to use your library to install C++ REST SDK through the NuGet package. You can link your users to our installation instructions page for further guidance on how to do that.

roschuma
Feb 3, 2015 at 8:43 AM
Edited Feb 3, 2015 at 9:23 AM
Ok I also installed C++ rest SDK to my application through NuGet package to use my library(A static library which is built using C++ rest SDK).But still getting those four linker errors.

I have just referenced my newly created lib file and the header file in my new C++ application. Am I missing anything more?
Mar 5, 2015 at 10:28 PM
Edited Mar 9, 2015 at 3:09 PM
I was successful with static linking when used the following steps:

"C++REST" For Release .lib:
  1. Configuration Properties -> General -> Target Extension : .lib (from .dll)
  2. Configuration Properties -> Configuration Type : Ststic library (.lib)
  3. Configuration Properties -> C/C+=-> Optimization-> Whole Program Optimization : No
  4. Configuration Properties -> C/C+=-> Preprocessor -> Processor Definitions : _NO_ASYNCRTIMP (added)
  5. Configuration Properties -> C/C+=-> Code Generation -> Runtime Library: Multi-threaded (/MT)
The result is : cpprest120_2_4_Release_Win32.lib


User Code:

The User Code must include also the Boost and SSL libraries.
Configuration Properties -> VC++Directories -> Library Directories :
C:\ ... \OpenSSL\lib\VC\static
C:\ ... \Boost\boost_1_57_0\stage\lib
C:\ ... \CppREST\lib\Release (<-- Copied the "cpprest120_2_4_Release_Win32.lib" here.)

The User Code must include the include directory:
Configuration Properties -> VC++Directories -> Include Directories :
C:\ ... \CppREST\include (<-- Copied the cpprest and pplx folders here whit *.h.)

add in:
Configuration Properties ->C/C+=-> Preprocessor -> Processor Definitions :
_NO_ASYNCRTIMP
_NO_PPLXIMP

add in:
Configuration Properties ->Linker ->
libeay32MT.lib
ssleay32MT.lib
crypt32.lib
bcrypt.lib


I do not understand why the "cpprest120_2_4_Release_Win32.lib" not contain all the required functions from it's libraries like the used SSL and Boost components?
It would be more logical (for me) if library A uses lib1.lib and lib2.lib to make libA.lib, and if somebody uses libA.lib it should not need to include in the project the lib1.lib and lib2.lib .?
Mar 22, 2015 at 10:09 AM
@SoosAntal,

I faced exactly same issue and totally agree with you... I have to include all the following libs on a user-project side to make it finally link statically... I wonder why you have to include Boost and SSL.. I'm not so sure about SSL, but I'm sure that Boost libs are statically linked when you build C++ REST SDK... As you see, I don't include them... I also wonder why don't you have to link against winhttp.lib: there is bunch of stuff relying on this...

cpprest120d_2_5.lib
winhttp.lib
crypt32.lib
bcrypt.lib


So finally this works on Windows desktop, but would this work on Linux?
Mar 22, 2015 at 5:29 PM
Edited Mar 22, 2015 at 5:29 PM
You are right, I also included the "winhttp.lib" in the code as #pragna:
#pragma comment(lib, "winhttp.lib")