Issue when updating to Visual Studio 2022: nuget packages are not working anymore, even for raw template projects (C++/winRT) - nuget-package

I recently updated my toolchain to Visual Studio 2022 to benefit from the latest and greatest of Microsoft's developer team.
Since then, my updated projects are struggling finding the headers from the nuget package I'm using (cpprestsdk):
When forcing the include path in the property of the project, the linker returns errors for unresolved external symbols:
1>App.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl utility::conversions::to_utf8string(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (__imp_?to_utf8string#conversions#utility##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEBV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##4##Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl utility::conversions::details::print_utf8string<wchar_t [18]>(wchar_t const (&)[18])" (??$print_utf8string#$$BY0BC#_W#details#conversions#utility##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEAY0BC#$$CB_W#Z)
1>App.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl web::uri::uri(wchar_t const *)" (__imp_??0uri#web##QEAA#PEB_W#Z) referenced in function "public: __cdecl <lambda_b8d78f1b6bbbf9eaa70df1523bc19c68>::operator()(class Concurrency::streams::basic_ostream<unsigned char>)const " (??R<lambda_b8d78f1b6bbbf9eaa70df1523bc19c68>##QEBA#V?$basic_ostream#E#streams#Concurrency###Z)
1>App.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl web::uri::uri(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (__imp_??0uri#web##QEAA#AEBV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std###Z) referenced in function "public: class Concurrency::task<class web::http::http_response> __cdecl web::http::client::http_client::request(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,class Concurrency::cancellation_token const &)" (?request#http_client#client#http#web##QEAA?AV?$task#Vhttp_response#http#web###Concurrency##AEBV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##0AEBVcancellation_token#6##Z)
...
1>C:\Users\arnau\source\repos\BlankAppTest\x64\Debug\BlankAppTest\BlankAppTest.exe : fatal error LNK1120: 26 unresolved externals
I also tried to start with a blank project from a predefined template (C++/winRT) but without success...
I have to confess I'm more focused on writing code than on project settings. I may have overlooked something in the setup process. However, the fact that the default project is not compiling correctly makes me think there's something wrong in my toolchain update.
So for the moment, I'm reverting to Visual Studio 2019...
Any help/pointers/suggestion on how to solve the issue will be greatly appreciated !
Best regards,
Arnaud

The issue is not directly related to NuGet and Visual Studio 2022 but more to the absence of update to the cpprestsdk library for the v143 target (thank you, #hans-passant, for your insight).
As suggested, I placed a request for an updated cpprestsdk NuGet package (v143) on GitHub (here).
Meanwhile, I'll continue to use Visual Studio 2019 ;)

Related

Boost log linker errors (LNK2001/LNK2019 unresolved external symbol) after upgrading to Windows 11 and rebuilding boost

I had boost compiled & working on my Visual Studio 2022 project. After the PC was upgraded and the OS changed to Windows 11 I attempted to re-build boost and use it with the same project. Now I get linker errors, and it seems like I have tried every suggested fix posted online. Somehow it seems like the lib files are not being found, even though I have confirmed the include and lib directories are included properly, and have tried rebuilding boost with many different configurations.
The boost build produces libboost_*.lib files, for example
libboost_log_setup-vc143-mt-gd-x32-1_78.lib
libboost_log_setup-vc143-mt-x32-1_78.lib
libboost_log-vc143-mt-gd-x32-1_78.lib
libboost_log-vc143-mt-x32-1_78.lib
Here are my boost build options
x86
b2 -j 16 --stagedir=stage/Win32 threading=multi --toolset=msvc-14.3
link=static runtime-link=shared --build-type=complete architecture=x86
address-model=32
x64
b2 -j 16 --stagedir=stage/x64 threading=multi --toolset=msvc-14.3
link=static runtime-link=shared --build-type=complete architecture=x64
--address-model=64
And my Visual Studio properties
C/C++->General->Additional Include Directories
C:\Program Files\Code Libraries\boost\boost_1_78_0
Linker->General->Additional Library Directories
C:\Program Files\Code
Libraries\boost\boost_1_78_0\stage$(Platform)\lib
And here's an example of the errors
1>Logging.obj : error LNK2019: unresolved external symbol "private: static unsigned int __cdecl boost::log::v2s_mt_nt62::attribute_name::get_id_from_string(char const *)" (?get_id_from_string#attribute_name#v2s_mt_nt62#log#boost##CAIPBD#Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt62::attribute_name::attribute_name(char const *)" (??0attribute_name#v2s_mt_nt62#log#boost##QAE#PBD#Z)
1>Logging.obj : error LNK2001: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::aux::stream_provider<char>::release_compound(struct boost::log::v2s_mt_nt62::aux::stream_provider<char>::stream_compound *)" (?release_compound#?$stream_provider#D#aux#v2s_mt_nt62#log#boost##SAXPAUstream_compound#12345##Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void * __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator new(unsigned int)" (??2impl#attribute#v2s_mt_nt62#log#boost##SAPAXI#Z) referenced in function "class boost::log::v2s_mt_nt62::attribute_value __cdecl boost::log::v2s_mt_nt62::attributes::make_attribute_value<unsigned int &>(unsigned int &)" (??$make_attribute_value#AAI#attributes#v2s_mt_nt62#log#boost##YA?AVattribute_value#123#AAI#Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator delete(void *,unsigned int)" (??3impl#attribute#v2s_mt_nt62#log#boost##SAXPAXI#Z) referenced in function __unwindfunclet$??$make_attribute_value#AAI#attributes#v2s_mt_nt62#log#boost##YA?AVattribute_value#123#AAI#Z$0
Edit: I also wanted to mention my preprocessor variables for Debug/Win32
WIN32
_DEBUG
_CONSOLE WIN32_LEAN_AND_MEAN
_WIN32_WINNT=0x0A00
I haven't been able to find a _WIN32_WINNT value for Windows 11, and I thought maybe that could be the problem. But I'm not entirely sure that matters.
The problem is that Boost, and Boost.Log in particular, was built for a different Windows version. You need to either:
Build Boost with _WIN32_WINNT defined to the same version as you define when you build your code.
Define BOOST_USE_WINAPI_VERSION when building your code to the Windows version Boost should target, which would be lower than your _WIN32_WINNT. Also define _WIN32_WINNT or BOOST_USE_WINAPI_VERSION macro to that version when building Boost.
To define the macro when building Boost add define=macro=value to the b2 command line. For example, define=_WIN32_WINNT=0x0A00.

Linking errors on VS2012 for CImageList and CBitmap apis

I am using mfc class CImageList in my project and using its APIs like Add(), Create() etc. It works fine with vs2010.
Now, I am upgrading the project to vs2012. It compiles and links fine for 32 bit platform, however throws below linking errors for 64 bit.
File1.obj : error LNK2019: unresolved external symbol imp_ImageList_ReplaceIcon referenced in function "public: int __cdecl CImageList::Add(struct HICON *)"
File2.obj : error LNK2019: unresolved external symbol __imp_ImageList_AddMasked referenced in function "public: int __cdecl CImageList::Add(class CBitmap *,unsigned long)"
Similarly, below error is thrown for calling CBitmap api.
File2.obj : error LNK2019: unresolved external symbol __imp_CreateMappedBitmap referenced in function "public: int __cdecl CBitmap::LoadMappedBitmap(unsigned int,unsigned int,struct _COLORMAP *,int)"
It seems that the libraries having these implementations might have been changed. However, I could not find any clue on how to resolve them.
Finally figured out the reason for this error.
ImageList_ReplaceIcon & CreateMappedBitmap symbols are present in comctl32.lib.
There was an older version comctl32.lib present in a path which was included in Additional Include Directories of my project settings.
So, instead of picking this lib from Microsoft SDK folder, the linker was picking from this directory and hence causing problems.

Mangled member function name different during dllimport

I'm getting some unresolved externals when importing a DLL of a project (Project 1) in a .exe project (Project 2) using MSVC 2013 (it compiles fine in Mingw 4.8.1):
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class chakra::Message * __thiscall chakra::PublisherSubscriberChannel::GetMessageA(unsigned __int64)" (__imp_?GetMessageA#PublisherSubscriberChannel#chakra##QAEPAVMessage#2#_K#Z) referenced in function "public: virtual void __thiscall Bar2::ProcessMessages(void)" (?ProcessMessages#Bar2##UAEXXZ)
test_wrap.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class chakra::Message * __thiscall chakra::PublisherSubscriberChannel::GetMessageA(unsigned __int64)" (__imp_?GetMessageA#PublisherSubscriberChannel#chakra##QAEPAVMessage#2#_K#Z)
The function GetMessage is a member function of class PublisherSubscriberChannel of namespace chakra in Project 1.
Examined the .exp and .dll file of Project 1 using dumpbin.exe /exports and found the function to be exported as ?GetMessage#PublisherSubscriberChannel#chakra##QAEPAVMessage#2#_K#Z whereas during importing it is looking for ?GetMessageA#PublisherSubscriberChannel#chakra##QAEPAVMessage#2#_K#Z as per the above error.
It happens only when I #include "Ogre.h" or any of the other Ogre headers in test_wrap.cxx file (which is a SWIG generated file).
Does anyone have any idea why the function name mismatch with the extra 'A'?

Having problems with yaml.cpp lib in c++

I am having a hard time trying to use yaml-cpp 0.3.0 on my project
I downloaded yaml, and built it like http://code.google.com/p/yaml-cpp/ said, with VS 9 2008 WIN 64. So, i got the yaml-cpp.dll and the yaml-cpp.lib
I have a c++ project on VS 2010 express, and i am trying to link the library:
I go to project properties - c/c++ general and additional include directories that have yaml-cpp header files. Then i go to linker and add path to my lib directory, then I go to linker - input and add my .lib file, then i go to VC++ Directories and add path to my lib directory in Library directories and Reference directories
Then i try to build this simple code:
std::ifstream fin("test.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
//do nothing yet
}
I got several linking problems, like this:
error LNK2019: unresolved external symbol "public: __thiscall YAML::Node::Node(void)" (??0Node#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
error LNK2019: unresolved external symbol "public: __thiscall YAML::Parser::~Parser(void)" (??1Parser#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
Can anyone help me? I am banging my head against a wall here.
As you said you've got a DLL from YAML, I assume you specified -DBUILD_SHARED_LIBS=ON when you built with VS2008, so you ended up with a lib for dynamic linking (to the DLL at runtime) rather than static linking (at compile time).
If the above is correct, it may be differences between VS2008 and VS2010 that are causing a problem. For example, see this post here. To quickly see if this is the cause, in your VS2010 project properties, set the Platform Toolset to V90 and see if that helps.
Also, make sure you compiled both projects for the same CPU - i.e. both for 32-bit or both for 64-bit.

Problems linking ACE in VC++

I've built ACE.dll and ACE.lib of the ACE library. But when I link it to my program, I get several errors like
Error 2 error LNK2019: unresolved
external symbol "void * __cdecl
ACE_OS::memcpy(void *,void const
*,unsigned int)" (?memcpy#ACE_OS##YAPAXPAXPBXI#Z)
referenced in function "public: void
__thiscall ACE_String_Base::set(char const
*,unsigned int,bool)" (?set#?$ACE_String_Base#D##QAEXPBDI_N#Z)
client_handler.obj Server
Error 3 error LNK2001: unresolved
external symbol "void * __cdecl
ACE_OS::memcpy(void *,void const
*,unsigned int)" (?memcpy#ACE_OS##YAPAXPAXPBXI#Z)
Server.obj
I've set include paths,lib paths, lib dependencies etc etc. I dont know what I'm missing :(
The linker is unable to find a definition for ACE_OS::memcpy. Check the documentation and see if you need to provide a suitable definition or not (or if there is one in the sample, if any samples are present at all).
This could also be because you've not defined a platform specific macro that would enable the default definition of this function. Please check the readme.

Resources