Static Link Casablanca / CPPREST SDK

I am trying to create a Windows VC ++ DLL (in VS 2015) statically linked to the Casablanca CPPREST SDK. That is, I would like to get a single DLL output containing the CPP REST library along with my code.

I referenced this thread, however it seems to be quite outdated (and has broken links):

https://katyscode.wordpress.com/2014/04/01/how-to-statically-link-the-c-rest-sdk-casablanca/

I tried to download the Casablanca repository from GitHub and compile the cpprestsdk140.static project that creates the lib file. The problem is I am getting multiple unresolved xrefs when linking it to my project.

Numerous people have commented on unresolved link errors in the above URL. There are also many threads on Github where people say they cannot link simple projects to a static library.

Does anyone have a clear set of steps that can help with this?

+3


source to share


3 answers


OK, I have combined a number of suggestions from different threads and followed the following set of steps to successfully link the CPP REST static library:

  • Download Casablanca SDK from https://github.com/Microsoft/cpprestsdk . (via GIT Clone or Zip).
  • Open VS solution and right click on cpprestsdk140.static properties.
  • In C ++ -> Preprocessor definitions add CPPREST_EXCLUDE_COMPRESSION . The complete list looks like this: _NO_ASYNCRTIMP; _ASYNCRT_EXPORT; _PPLX_EXPORT; WIN32; _MBCS; _USRDLL; CPPREST_EXCLUDE_COMPRESSION;% (PreprocessorDefinitions)
  • In Library -> General -> Additional Dependencies, add crypt32.lib; winhttp.lib; (see https://github.com/Microsoft/cpprestsdk/issues/344 )
  • Click OK, then create the cpprestsdk140.static project. In the Binaries directory, you will get libcpprest140d_2_9.lib (for building Debug).

Now, in your own project:



  • If you've used the Nuget CPPREST version before, first make sure you remove any references in the Nuget Package Manager.
  • Right click your project properties and go to C ++ -> Additional Include Directories and enter the path for the CPUREST SDK include files. They are currently located in the cpprestsdk \ Release \ include directory.
  • Now go to C ++ -> Preprocessor definitions, add _NO_ASYNCRTIMP (see https://github.com/Microsoft/cpprestsdk/issues/124 ).
  • Go to Linker -> Input and add libcpprest140d_2_9.lib (along with the pathname if applicable). For the release version, it looks like you need to add crypt32.lib as well ; winhttp.lib .
  • Build your project and hopefully all is well;)

I hope this helps someone (I'm sure it will)!

+3


source


One more addition to the simple answer: If you are using the http_listener class in your project, you probably need Httpapi.lib to fix linker errors.

And also I want to suggest an easier way to compile the static cpprestdk library. I have used it successfully to build my project in VS2017.



  • install vcpkg from https://github.com/Microsoft/vcpkg
  • Compile cpprestsdk using the following commands: vcpkg install cpprestsdk: x86-windows-static vcpkg install cpprestsdk: x64-windows-static
  • Follow the second part of Simple Guy's answer, starting with your project settings. Also, use my recommendations above and BobC to fix linker errors.

Enjoy!

+4


source


In addition to what Simple Guy said, you probably have to add bcrypt.lib to Linker-> Input-> Additional Dependencies, as the OAuth1.obj file in CPPRest depends on some of these functions.

+3


source







All Articles