cpprestsdk
cpprestsdk copied to clipboard
websocket library link error with vcpkg install
I've install cpprestsdk with vcpkg, and executed vcpkg.exe integrate install. But when I #include <cpprestsdk/ws_client.h> in visual studio 2019, It has some link error.
Error | LNK2019 | unresolved external symbol "__declspec(dllimport) public: class Concurrency::task<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > __cdecl web::websockets::client::websocket_incoming_message::extract_string(void)const " (__imp_?extract_string@websocket_incoming_message@client@websockets@web@@QEBA?AV?$task@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concurrency@@XZ) referenced in function "public: void __cdecl <lambda_d084fb8f680c72cb130d66a02d9b5b24>::operator()(class web::websockets::client::websocket_incoming_message)const " (??R<lambda_d084fb8f680c72cb130d66a02d9b5b24>@@QEBAXVwebsocket_incoming_message@client@websockets@web@@@Z)
Error | LNK2019 | unresolved external symbol "__declspec(dllimport) public: class Concurrency::task<class web::websockets::client::websocket_incoming_message> __cdecl web::websockets::client::details::websocket_client_task_impl::receive(void)" (__imp_?receive@websocket_client_task_impl@details@client@websockets@web@@QEAA?AV?$task@Vwebsocket_incoming_message@client@websockets@web@@@Concurrency@@XZ) referenced in function "public: class Concurrency::task<class web::websockets::client::websocket_incoming_message> __cdecl web::websockets::client::websocket_client::receive(void)" (?receive@websocket_client@client@websockets@web@@QEAA?AV?$task@Vwebsocket_incoming_message@client@websockets@web@@@Concurrency@@XZ)
Error | LNK2019 | unresolved external symbol "__declspec(dllimport) public: void __cdecl web::websockets::client::details::websocket_client_task_impl::close_pending_tasks_with_error(class web::websockets::client::websocket_exception const &)" (__imp_?close_pending_tasks_with_error@websocket_client_task_impl@details@client@websockets@web@@QEAAXAEBVwebsocket_exception@345@@Z) referenced in function __catch$??R<lambda_c8bcff768c1b7a6664919177f490ce2a>@@QEBAXV?$task@X@Concurrency@@@Z$0
Error | LNK2019 | unresolved external symbol "__declspec(dllimport) public: __cdecl web::websockets::client::details::websocket_client_task_impl::websocket_client_task_impl(class web::websockets::client::websocket_client_config)" (__imp_??0websocket_client_task_impl@details@client@websockets@web@@QEAA@Vwebsocket_client_config@234@@Z) referenced in function "void __cdecl std::_Construct_in_place<class web::websockets::client::details::websocket_client_task_impl,class web::websockets::client::websocket_client_config>(class web::websockets::client::details::websocket_client_task_impl &,class web::websockets::client::websocket_client_config &&)" (??$_Construct_in_place@Vwebsocket_client_task_impl@details@client@websockets@web@@Vwebsocket_client_config@345@@std@@YAXAEAVwebsocket_client_task_impl@details@client@websockets@web@@$$QEAVwebsocket_client_config@345@@Z)
Here is my sample codes:
#include
#include <cpprest/http_client.h> #include <cpprest/ws_client.h> using namespace web; using namespace web::websockets::client; int main(int argc, const char * argv[]) { // insert code here... websocket_client_config config; config.headers().add(U("Sec-WebSocket-Protocol"), "protoo"); websocket_client client(config); std::string body_str("hello");
try { client.connect(U("wss://echo.websockets.org")).wait(); auto receive_task = client.receive().then([body_str](websocket_incoming_message ret_msg) { auto ret_str = ret_msg.extract_string().get(); }); websocket_outgoing_message msg; msg.set_utf8_message(body_str); client.send(msg).wait(); receive_task.wait(); client.close().wait(); } catch (const websocket_exception& e) { printf("%s", e.what()); throw; }
return 0; }
can you post your build system? Are you using msbuild or cmake?
can you post your build system? Are you using msbuild or cmake?
I use cmake with add_library() to include library
I'm using vcpkg with windows and visual studio. Has the same problem.
remove and
vcpkg install cpprestsdk[websockets]:x64-windows --recurse