본문 바로가기

IT/삽질

c++ rest sdk - static link (msvc2015)

SDK Github

https://github.com/Microsoft/cpprestsdk


물론 그냥 사용하려면 누겟 패키지 관리자에서 설치 후 사용해도 아무런 문제가 없을 것이다.

다만, 스태틱 링킹 하려면 몇가지 준비가 필요하다.


빌드

스태틱 빌드를 하기 위해서는 https://github.com/Microsoft/cpprestsdk 에서 소스 받고 빌드 해야 한다.

cpprestsdk140.sln 솔루션 파일 열어서, 아래의 프로젝트를 빌드하면 된다.



결과물

빌드 결과물은 아래의 경로에 생성된다.

cpprestsdk-2.10.0\Binaries\x64\Release\libcpprest140_2_10.lib

cpprestsdk-2.10.0\Binaries\x64\Debug\libcpprest140d_2_10.lib



Dependency

cpprestsdk 는 zlib 를 필요로 하기에 zlib를 static 빌드 해야 한다. 결국.. 받아서 빌드해야 한다.


소스는 https://github.com/madler/zlib 에 있고

솔루션 파일은 zlib/tree/master/contrib/vstudio/vc14 에 있다.


아무 사이트나 가서 static 빌드된 것을 받아서 링킹했더니, code generation(싱글스래드기반) 이 맞지 않아 링크 경고가 발생했다. 

깔금해야 하니 사용하던 프로젝트 환경에 맞게 빌드하여 결과물을 뽑아서 링킹하는게 맞다고 생각한다.


종속 해결 후 LIB 참조 예제

전처리기(Preprocessor) 에서 
_NO_ASYNCRTIMP; _USRDLL; REDSHELL_EXPORTS
를 선언해줘야 한다.
#pragma comment ( lib, "crypt32.lib")
#pragma comment ( lib, "bcrypt.lib")
#pragma comment ( lib, "ws2_32.lib")
#pragma comment ( lib, "winhttp.lib")

#ifdef _DEBUG
#pragma comment ( lib, "../cpprest/Debug/zlibd_64.lib")
#pragma comment ( lib, "../cpprest/Debug/libcpprest140d_2_10.lib")
#else
#pragma comment ( lib, "../cpprest/Release/zlib_64.lib")
#pragma comment ( lib, "../cpprest/Release/libcpprest140_2_10.lib")
#endif

#include "cpprest/http_client.h"

// 마음껏 사용하자

참조링크

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


기타링크

casablanca static lib bin

bcrypt.lib

https://www.google.co.kr/search?newwindow=1&q=zlib+64bit&sa=X&ved=0ahUKEwjOye_G-cHXAhUBxbwKHdSYCkAQ1QIIdSgE&biw=1920&bih=900

https://zlib.net/

https://github.com/madler/zlib

https://www.google.co.kr/search?newwindow=1&q=zlib+visual+studio+2015&sa=X&ved=0ahUKEwjLxdi1-sHXAhXIVbwKHVY3Ak8Q1QIIfigF&biw=1920&bih=900

https://www.lesstif.com/pages/viewpage.action?pageId=22643935

https://francescofoti.com/2013/12/compiling-the-zlib-compression-library-with-visual-studio-2013/

http://blog.bagesoft.com/280

https://kldp.org/node/91208

https://github.com/Microsoft/cpprestsdk/wiki/How-to-use-the-C---Rest-SDK-NuGet-package

https://stackoverflow.com/questions/39594745/http-client-get-request-method-not-working-in-cpprest-of-casablanca-sdk

https://stackoverflow.com/questions/41763407/linker-errors-with-casablanca-in-vs2015-while-trying-to-build-a-simple-http-list



'IT > 삽질' 카테고리의 다른 글

pthread 윈도우 라이브러리  (1) 2018.03.08