微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在构建时向C ++项目添加nuget软件包会在生成LNK2001错误

如何解决在构建时向C ++项目添加nuget软件包会在生成LNK2001错误

我有一个使用cpprestsdk的C ++ Visual Studio 2015项目。我使用工具/ Nuget程序包管理器在Visual Studio中为cpprest添加了nuget程序包。我对来自cpprest的包含文件没有任何错误,并且Visual Studio可以识别它们,问题是,当我尝试构建项目时,会遇到很多LNK2001错误,例如:

Error   LNK2001 unresolved external symbol "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl utility::conversions::to_string_t(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (?to_string_t@conversions@utility@@YA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@$$QEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) check-cpprest-nug   D:\Work\visual-projects\check-cpprest-nug\check-cpprest-nug\check-cpprest-nug.obj   1   

我以为此链接tutorial之后是自动的,该链接最初是针对C#的,但是我找不到C ++特有的任何内容

我是否缺少项目属性中的任何步骤?

**编辑**

我正在添加一段代码以提供更多的上下文,但是我认为问题可能与链接有关或由于项目配置而引起。当cpprest是静态链接而不是使用nuget链接时,该项目就可以正常工作。

std::ostringstream msg;

    utility::string_t address(U("https://*** --- ***"));
    
    http::uri uri = http::uri(address);

    http::client::http_client req(uri);

    try
    {
        auto response = req.request(http::methods::GET).get();

        auto status = response.status_code();

        if (status != http::status_codes::OK)
        {
            msg << "COUNTER PARTY LOOKUP :: Http Request Could not be completed successfully with error code: " << status << "\n";

            throw std::runtime_error(msg.str());
        }

        json::value obj = response.extract_json().get();

        std::cout << utility::conversions::to_utf8string( obj.serialize() )<< std::endl;

    }
    catch (std::exception &e)
    {

        msg << "COUNTER PARTY LOOKUP :: Problem opening connection. Try again later." << std::endl;
    }

解决方法

由于我没有您的代码,也无法跟踪问题的具体内容,所以这是我的建议

建议

您应该静态连接到cpprestsdk,对于我来说,我应该在预处理中添加_NO_ASYNCRTIMP,然后将bcrypt.libwinhttp.lib添加到项目的链接器中。

要实现所有这些功能,您应该安装一个名为cpprestsdk.v140.windesktop.msvcstl.static.rt-static的nuget程序包。

此软件包将在安装时自动将这些点添加到您的项目中。

记住以包括以下头文件:

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

注意:您应使用Debug/Release配置和win32/x64平台。将平台工具集保持为Visual Studio 2015 v140

此外,如果它不能解决您的问题,建议您与我们共享代码,以便我们更快地解决问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。