microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.89k stars 1.63k forks source link

Problem with Static Lib in Visual Studio 2015 #377

Open ghost opened 7 years ago

ghost commented 7 years ago

I am relatively new to c++ and the cpprestsdk._

I am using an empty c++ project in visual studio 2015. I build myself the 32 Bit version of the libraries and I get weird errors when trying to build a small test project.

(the #define is a fix to a problem I had with the dllimport stuff)

#define _NO_ASYNCRTIMP

#include <iostream>
#include <cpprest/ws_client.h>

using namespace std;
using namespace web;
using namespace web::websockets::client;

int main() {
    websocket_client client;
    client.connect(utility::conversions::to_string_t("ws://echo.websocket.org")).wait();

    websocket_outgoing_message out_msg;
    out_msg.set_utf8_message("test");
    client.send(out_msg).wait();

    client.receive().then([](websocket_incoming_message in_msg) {
        return in_msg.extract_string();
    }).then([](string body) {
        cout << body << endl; // test
    }).wait();

    client.close().wait();

    return 0;
}
1>NetworkManager.obj : error LNK2019: 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@@$$QAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) referenced in function _main
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: __thiscall web::uri::uri(wchar_t const *)" (??0uri@web@@QAE@PB_W@Z) referenced in function "public: __thiscall web::web_proxy::web_proxy(void)" (??0web_proxy@web@@QAE@XZ)
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: __thiscall web::uri::uri(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0uri@web@@QAE@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function _main
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: __thiscall web::details::win32_encryption::~win32_encryption(void)" (??1win32_encryption@details@web@@QAE@XZ) referenced in function "public: __thiscall web::credentials::~credentials(void)" (??1credentials@web@@QAE@XZ)
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: class Concurrency::task<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > __thiscall web::websockets::client::websocket_incoming_message::extract_string(void)const " (?extract_string@websocket_incoming_message@client@websockets@web@@QBE?AV?$task@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concurrency@@XZ) referenced in function "public: class Concurrency::task<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > __thiscall <lambda_44cc3b124a167037209ca6deee520cd1>::operator()(class web::websockets::client::websocket_incoming_message)const " (??R<lambda_44cc3b124a167037209ca6deee520cd1>@@QBE?AV?$task@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concurrency@@Vwebsocket_incoming_message@client@websockets@web@@@Z)
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: __thiscall web::websockets::client::details::websocket_client_task_impl::websocket_client_task_impl(class web::websockets::client::websocket_client_config)" (??0websocket_client_task_impl@details@client@websockets@web@@QAE@Vwebsocket_client_config@234@@Z) referenced in function "public: __thiscall std::_Ref_count_obj<class web::websockets::client::details::websocket_client_task_impl>::_Ref_count_obj<class web::websockets::client::details::websocket_client_task_impl><class web::websockets::client::websocket_client_config>(class web::websockets::client::websocket_client_config &&)" (??$?0Vwebsocket_client_config@client@websockets@web@@@?$_Ref_count_obj@Vwebsocket_client_task_impl@details@client@websockets@web@@@std@@QAE@$$QAVwebsocket_client_config@client@websockets@web@@@Z)
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: class Concurrency::task<class web::websockets::client::websocket_incoming_message> __thiscall web::websockets::client::details::websocket_client_task_impl::receive(void)" (?receive@websocket_client_task_impl@details@client@websockets@web@@QAE?AV?$task@Vwebsocket_incoming_message@client@websockets@web@@@Concurrency@@XZ) referenced in function "public: class Concurrency::task<class web::websockets::client::websocket_incoming_message> __thiscall web::websockets::client::websocket_client::receive(void)" (?receive@websocket_client@client@websockets@web@@QAE?AV?$task@Vwebsocket_incoming_message@client@websockets@web@@@Concurrency@@XZ)
1>NetworkManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall web::websockets::client::details::websocket_client_task_impl::close_pending_tasks_with_error(class web::websockets::client::websocket_exception const &)" (?close_pending_tasks_with_error@websocket_client_task_impl@details@client@websockets@web@@QAEXABVwebsocket_exception@345@@Z) referenced in function __catch$??R<lambda_6faaa49c60b61750ef16c4ff707b1ae7>@@QBEXV?$task@X@Concurrency@@@Z$0
AhmadChaker commented 6 years ago

In addition to the _NO_ASYNCRTIMP preprocessor value, you need to add the following libs to the linker line: bcrypt.lib and winhttp.lib. This has resolved the issue for me.