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
8.01k stars 1.66k forks source link

unresolved external (Static lib) #1442

Open Syn9673 opened 4 years ago

Syn9673 commented 4 years ago

Hi i am using cpprestsdk:x64-static-windows. And i keep getting

main.obj : error LNK2019: unresolved external symbol "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 " (?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 "private: virtual class Concurrency::task<class std::basic_string<char,struct std:
:char_traits<char>,class std::allocator<char> > > __cdecl std::_Func_impl_no_alloc<class <lambda_27d4f768c7ecd1f39c49d7ee0e9e3e30>,class Concurrency::task<class std::basic_strin
g<char,struct std::char_traits<char>,class std::allocator<char> > >,class web::websockets::client::websocket_incoming_message>::_Do_call(class web::websockets::client::websocket
_incoming_message &&)" (?_Do_call@?$_Func_impl_no_alloc@V<lambda_27d4f768c7ecd1f39c49d7ee0e9e3e30>@@V?$task@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concur
rency@@Vwebsocket_incoming_message@client@websockets@web@@@std@@EEAA?AV?$task@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concurrency@@$$QEAVwebsocket_incomin
g_message@client@websockets@web@@@Z) [C:\Users\AJ\Desktop\lib\build\test.vcxproj]
main.obj : error LNK2019: unresolved external symbol "public: __cdecl web::websockets::client::details::websocket_client_task_impl::websocket_client_task_impl(class web::websock
ets::client::websocket_client_config)" (??0websocket_client_task_impl@details@client@websockets@web@@QEAA@Vwebsocket_client_config@234@@Z) referenced in function "void __cdecl s
td::_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) [C:\Users\AJ\Desktop\lib\build\tes
t.vcxproj]
main.obj : error LNK2019: unresolved external symbol "public: class Concurrency::task<class web::websockets::client::websocket_incoming_message> __cdecl web::websockets::client:
:details::websocket_client_task_impl::receive(void)" (?receive@websocket_client_task_impl@details@client@websockets@web@@QEAA?AV?$task@Vwebsocket_incoming_message@client@websock
ets@web@@@Concurrency@@XZ) referenced in function "void __cdecl conn(class Napi::CallbackInfo const &)" (?conn@@YAXAEBVCallbackInfo@Napi@@@Z) [C:\Users\AJ\Desktop\lib\build\test
.vcxproj]
main.obj : error LNK2019: unresolved external symbol "public: void __cdecl 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@@QEAAXAEBVwebsocket_exception@345@@
Z) referenced in function __catch$??R<lambda_c8bcff768c1b7a6664919177f490ce2a>@@QEBAXV?$task@X@Concurrency@@@Z$0 [C:\Users\AJ\Desktop\lib\build\test.vcxproj]
C:\Users\AJ\Desktop\lib\build\Release\test.node : fatal error LNK1120: 4 unresolved externals [C:\Users\AJ\Desktop\lib\build\test.vcxproj]

I am compiling this as a nodejs module, this is my binding.gyp:

{
  "targets": [
    {
      "target_name": "test",
      "sources": [
        "main.cpp"
      ],
      "include_dirs": [
        "<!@(node -p \"require('node-addon-api').include\")"
      ],
      "libraries": [
        "cpprest_2_10.lib",
        "winhttp.lib",
        "bcrypt.lib",
        "zlib.lib",
        "crypt32.lib",
      ],
      "defines": [
        "NAPI_DISABLE_CPP_EXCEPTIONS",
        "_WINSOCK_DEPRECATED_NO_WARNINGS",
        "_NO_ASYNCRTIMP",
        "_MBCS",
        "_USRDLL",
        "_NO_PPLXIMP",
        "%(PreprocessorDefinitions)"
      ],
      'msvs_settings': {
        'VCLinkerTool': {
          'AdditionalOptions': [ '/NODEFAULTLIB:libary' ]
        },

        'VCCLCompilerTool': {
          'AdditionalOptions': [ '/EHsc' ]
        }
      }
    }
  ]
}

i was wondering why i keep getting that when i do this:

void conn(const CallbackInfo& info)
{
  websocket_client client;
  client.connect(U("wss://gateway.discord.gg/?v=6"));

  client.receive()
  .then([](websocket_incoming_message msg)
  {
    return msg.extract_string();
  })
  .then([](string msg)
  {
    cout << msg << endl;
  });
}
fxfire commented 4 years ago

^ Same here, static windows x64 build does throw the above errors. Using the none-static version works fine though.

fxfire commented 4 years ago

Seeing that it still keeps copying the libcrypto-1_1-x64.dll to my folder, I'd say that is a hint where the bug comes from ... I doubt we are the only one(s) with that problem ...

Syn9673 commented 4 years ago

yeah i doubt it as well

fxfire commented 4 years ago

I finally had a bit time to look into it. Seems the CMakeLists.txt is setup a bit wrong... for our purpose "windows x64 static" build

Anyway, you need to do this in order to make it work:

then it compiles

Syn9673 commented 4 years ago

i'll test it

Syn9673 commented 4 years ago

it only reduced them to 4 unresolved.

main.obj : error LNK2001: unresolved external symbol "public: void __cdecl web::websockets::client::details::websocket_
client_task_impl::close_pending_tasks_with_error(class web::websockets::client::websocket_exception const &)" (?close_p
ending_tasks_with_error@websocket_client_task_impl@details@client@websockets@web@@QEAAXAEBVwebsocket_exception@345@@Z)
[C:\Users\alexa\Desktop\Projects\discord-cpp-js\build\test.vcxproj]
main.obj : error LNK2001: unresolved external symbol "public: class Concurrency::task<class web::websockets::client::we
bsocket_incoming_message> __cdecl web::websockets::client::details::websocket_client_task_impl::receive(void)" (?receiv
e@websocket_client_task_impl@details@client@websockets@web@@QEAA?AV?$task@Vwebsocket_incoming_message@client@websockets
@web@@@Concurrency@@XZ) [C:\Users\alexa\Desktop\Projects\discord-cpp-js\build\test.vcxproj]
main.obj : error LNK2001: unresolved external symbol "public: __cdecl web::websockets::client::details::websocket_clien
t_task_impl::websocket_client_task_impl(class web::websockets::client::websocket_client_config)" (??0websocket_client_t
ask_impl@details@client@websockets@web@@QEAA@Vwebsocket_client_config@234@@Z) [C:\Users\alexa\Desktop\Projects\discord-
cpp-js\build\test.vcxproj]
main.obj : error LNK2001: unresolved external symbol "public: class Concurrency::task<class std::basic_string<char,stru
ct std::char_traits<char>,class std::allocator<char> > > __cdecl web::websockets::client::websocket_incoming_message::e
xtract_string(void)const " (?extract_string@websocket_incoming_message@client@websockets@web@@QEBA?AV?$task@V?$basic_st
ring@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Concurrency@@XZ) [C:\Users\alexa\Desktop\Projects\discord-cpp-js\bu
ild\test.vcxproj]
C:\Users\alexa\Desktop\Projects\discord-cpp-js\build\Release\test.node : fatal error LNK1120: 4 unresolved externals [C
:\Users\alexa\Desktop\Projects\discord-cpp-js\build\test.vcxproj]
fxfire commented 4 years ago

I haven't used websockets yet, I guess that's why I am not getting these lines. Afaik cpprestsdk uses the Websocketpp lib for that, https://github.com/zaphoyd/websocketpp/issues/623 But I'm not sure what libs that one require to link .... wild guesses: Bcrypt.lib,wldap32.lib,AdvAPI32.Lib,User32.Lib,Gdi32.Lib,winhttp.lib

Are you using VS2019 to compile ? If so, you should add this into the .vcxproj, else it was never using the static versions for me: grafik

NLKNguyen commented 3 years ago

You probably need to install the WebSockets feature explicitly.

.\vcpkg install cpprestsdk[websockets]:x64-windows --recurse
anluoma commented 3 years ago

I agree with @NLKNguyen websockets feature is needed when installing cpprestsdk. So that should be used and this could be closed AFAIK?