静态链接 Casablanca/CPPREST SDK [英] Statically linking Casablanca/CPPREST SDK
问题描述
我正在尝试创建一个静态链接到 Casablanca CPPREST SDK 的基于 Windows 的 VC++ DLL(在 VS 2015 中).也就是说,我想要一个包含 CPP REST 库和我的代码的 DLL 输出.
I am trying to create a Windows-based VC++ DLL (in VS 2015) that statically links to the Casablanca CPPREST SDK. That is, I would like a single DLL output which contains the CPP REST library along with my code.
我已经提到了这个线程,但它似乎过时了(并且链接已断开):
I have referred to this thread, however it seems rather dated (and has broken links):
https://katyscode.wordpress.com/2014/04/01/how-to-statically-link-the-c-rest-sdk-casablanca/
我尝试从 GitHub 下载 Casablanca 存储库并编译生成 lib 文件的cpprestsdk140.static"项目.问题是在将它与我的项目链接时,我得到了许多未解决的外部变量.
I have tried to download the Casablanca repo from GitHub and compile the "cpprestsdk140.static" project which produces a lib file. The problem is I get a number of unresolved externals when linking it with my project.
许多人对上述 URL 中未解决的链接错误发表了评论.Github 上也有很多人说他们不能将简单的项目与静态库链接.
Numerous people have commented on the unresolved link errors in the above-mentioned URL. There are also numerous threads on Github with people saying they cannot link simple projects with the static library.
有没有人有一套明确的步骤可以帮助解决这个问题?
Does anyone have a clear set of steps that can help resolve this?
推荐答案
好的,我汇集了来自各个线程的一些建议,并按照以下步骤成功链接到 CPP REST 静态库:
OK, I pooled together a number of suggestions from the various threads and have the following set of steps in order to successfully link to the CPP REST static library:
- 从 https://github.com/Microsoft/cpprestsdk 下载 Casablanca SDK.(通过 GIT Clone 或 Zip).
- 打开 VS 解决方案并右键单击 cpprestsdk140.static 的属性.
- 在C++ -> 预处理器定义中,添加CPPREST_EXCLUDE_COMPRESSION.完整列表如下所示:_NO_ASYNCRTIMP;_ASYNCRT_EXPORT;_PPLX_EXPORT;WIN32;_MBCS;_USRDLL;CPPREST_EXCLUDE_COMPRESSION;%(PreprocessorDefinitions)
- 在Librarian -> General -> Additional dependencies中,添加crypt32.lib;winhttp.lib;(请参阅 https://github.com/Microsoft/cpprestsdk/issues/344)
- 按 OK,然后构建 cpprestsdk140.static 项目.您将在 Binaries 目录中得到一个 libcpprest140d_2_9.lib(用于调试构建).
- Download Casablanca SDK from https://github.com/Microsoft/cpprestsdk. (via GIT Clone or Zip).
- Open the VS solution and right-click on the properties of the cpprestsdk140.static.
- In the C++ -> Preprocessor definitions, add CPPREST_EXCLUDE_COMPRESSION. The full list looks like: _NO_ASYNCRTIMP;_ASYNCRT_EXPORT;_PPLX_EXPORT;WIN32;_MBCS;_USRDLL;CPPREST_EXCLUDE_COMPRESSION;%(PreprocessorDefinitions)
- In Librarian -> General -> Additional dependencies, add crypt32.lib;winhttp.lib; (See https://github.com/Microsoft/cpprestsdk/issues/344)
- Press OK, then build the cpprestsdk140.static project. You will end up with a libcpprest140d_2_9.lib (for Debug build) in the Binaries directory.
现在,在您自己的项目中:
Now, in your own project:
- 如果您之前使用过 Nuget 版本的 CPPREST,请首先确保删除 Nuget 包管理器中的所有引用.
- 右键单击您的项目属性并转到 C++ -> 其他包含目录,然后输入 CPPREST SDK 包含文件的路径.它们目前位于 cpprestsdk\Release\include.
- 现在转到C++ -> 预处理器定义,添加_NO_ASYNCRTIMP(参见https://github.com/Microsoft/cpprestsdk/issues/124).
- 转到链接器 -> 输入并添加libcpprest140d_2_9.lib(以及路径名,如果适用).对于发布版本,您似乎还需要添加 crypt32.lib;winhttp.lib.
- 构建您的项目,希望一切顺利;)
- If you have previously used the Nuget version of CPPREST, firstly ensure 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 CPPREST SDK include files. They currently reside in cpprestsdk\Release\include.
- 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 pathname, if applicable). For the release version, it appears you also need to add crypt32.lib;winhttp.lib.
- Build your project and hopefully all is well ;)
我希望这对某人有所帮助(我相信它会)!
I hope this helps someone (I'm sure it will)!
这篇关于静态链接 Casablanca/CPPREST SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!