Unersolved external symbol
I've installed nuget package and added lib in linker input code:
#include "stdafx.h"
#include "LoginApi.h"
#include <cpprest/http_client.h>
LoginApi::LoginApi()
{
web::http::client::http_client client(L"https://ex.com");
web::http::http_request request;
request.headers().add(L"User-Agent", L"~");
std::stringstream ReqBody;
std::string ReqBodyS;
ReqBody << "login=" << "" << "&pass=" << "" << "&type=2";
ReqBodyS = ReqBody.str();
request.set_body(ReqBodyS);
request.set_method(web::http::methods::POST);
request.headers().set_content_type(U("application/x-www-form-urlencoded"));
client.request(request).then([](web::http::http_response response)
{
if (response.status_code() == web::http::status_codes::OK)
{
if (response.headers()[web::http::header_names::pragma].c_str()[0] != '\0')
{
~~~
}
}
else
MessageBoxA(nullptr, "Connection error!", "", MB_OK);
});
}
And i got
unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::header_names::pragma" (?pragma@header_names@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)
Error 1 error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::GET" (?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)
Error 2 error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::POST" (?POST@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)
The NuGet package should automatically add the lib to your link libraries assuming you've selected the correct NuGet package for your compiler settings. What VS version are you using and what NuGet package did you add?
I had a similar issue and the cause is that my build configurations are not named "Debug" and "Release". If your configs are named otherwise, the linker will fail. To fix this you can just add your build config names to the targets file in the package directory.
I don't know if this is something that can be fixed or if it's a known limtiation of VS/Nuget, but it would have been helpful to have a note or something on the tutorial page.
I had the same issue. I compile my project and cpprest by cmake with MSVC(VS2015 Community 14.0.25123.00 Update 2). I had set CMAKE_BUILD_TYPE=Debug, and build the project and cpprest with command
cmake --build . --config Debug
But it not works, the error is
error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,stru
ct std::
char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::GET" (?GET@methods@http@web@@2V?$basic_
string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)
Then I open the cpprest_2_8.dll by depends.exe, I found the line
[+ ] 41 (0x0029) 40 (0x0028) ?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B
At last I open the cpprest_2_8.lib, I also found 3 lines about the GET symbol
__imp_?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B
__imp_?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B
?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B
Could you post your CMakeLists.txt here? This sounds like things aren't getting linked properly.
I currently am also having unresolved external symbol. I followed all the steps for statically linking and building a .lib file for cpprestsdk. I have also included the include and lib directory and even tried doing #pragma comment(lib, "cpprest140d_2_8.lib") in my source file. It still will not resolve the library properly. Previous versions of the cpprestsdk worked just fine.
I am having the same issue. I am trying to build DLL and will statically link the cpprest140d_2_8.lib to my DLL Project. Ihave also added the include and .lib directory PATH to my Proejct settings and also specify the "cpprest140d_2_8.lib" under Linker->Input options. When I try to Build the following Code
#include "stdafx.h"
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <cpprest/json.h>
void test_runner()
{
web::http::http_request request(web::http::methods::GET);
web::json::value data_obj;
}
I receive following error:
error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const web::http::methods::GET" (?GET@methods@http@web@@2V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@B)
Please help as I cant move forward from here.
Thanks in advance.
If you want to static link to the cpprestsdk, you should add _NO_ASYNCRTIMP in the preprocess.
Thanx for the help, I don't have access to computer right now but when I will work on it, I will definitely write back for help.
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.
hey hi all, I am getting the same error even after following the above steps....I also installed the Nuget package , VS15 and the version is 2.9.1.1.
For reference, also see https://stackoverflow.com/questions/44905708/statically-linking-casablanca-cpprest-sdk.
Fixed by vcpkg existing :)