DerekGn / WinBle

A set of C++ classes to abstract the win32 api calls required to enumerate and interact with ble devices on windows
MIT License
46 stars 17 forks source link

Unable to compile using VS 2022 #17

Closed mikechiarappa closed 2 years ago

mikechiarappa commented 2 years ago

Hi, I'm able to partialy compile the project using VS2022 Community: subproject WinBleLib compiles fine, but WinBleTest gives me error C2280. The project fork David-Sackstein/WinBle compiles correctly. The issue seems related to the adoption of . Do you have some suggestion or hint about ? Thx in advance

DerekGn commented 2 years ago

Hey could you send the build log. I can build correctly with VS2019 and VS2022

mikechiarappa commented 2 years ago

Here it is: Rebuild started... 1>------ Rebuild All started: Project: WinBleLib, Configuration: Debug Win32 ------ 1>BleDevice.cpp 1>BleDeviceContext.cpp 1>BleDeviceEnumerator.cpp 1>BleDeviceInfo.cpp 1>BleException.cpp 1>BleFunctions.cpp 1>BleGattCharacteristic.cpp 1>BleGattCharacteristicValue.cpp 1>BleGattDescriptor.cpp 1>BleGattDescriptorValue.cpp 1>BleGattNotificationData.cpp 1>BleGattService.cpp 1>CallbackContext.cpp 1>HandleWrapper.cpp 1>Utility.cpp 1>Generating Code... 1>WinBleLib.vcxproj -> C:\Users\m.chiarappa\source\repos\WinBle-master\src\Debug\WinBleLib.lib 2>------ Rebuild All started: Project: WinBleTest, Configuration: Debug Win32 ------ 2>WinBleTest.cpp 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\xmemory(682,47): error C2280: 'std::unique_ptr<BleGattService,std::default_delete>::unique_ptr(const std::unique_ptr<BleGattService,std::default_delete> &)': attempting to reference a deleted function 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\memory(3291): message : see declaration of 'std::unique_ptr<BleGattService,std::default_delete>::unique_ptr' 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\memory(3291,5): message : 'std::unique_ptr<BleGattService,std::default_delete>::unique_ptr(const std::unique_ptr<BleGattService,std::default_delete> &)': function was explicitly deleted 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(660): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,const std::unique_ptr<BleGattService,std::default_delete>&>(_Alloc &,_Objty const ,const std::unique_ptr<BleGattService,std::default_delete> &)' being compiled 2> with 2> [ 2> _Alloc=std::allocator<std::_List_node<std::unique_ptr<BleGattService,std::default_delete>,std::_Default_allocator_traits<std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::void_pointer>>, 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Objty=std::unique_ptr<BleGattService,std::default_delete> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(660): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,const std::unique_ptr<BleGattService,std::default_delete>&>(_Alloc &,_Objty const ,const std::unique_ptr<BleGattService,std::default_delete> &)' being compiled 2> with 2> [ 2> _Alloc=std::allocator<std::_List_node<std::unique_ptr<BleGattService,std::default_delete>,std::_Default_allocator_traits<std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::void_pointer>>, 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Objty=std::unique_ptr<BleGattService,std::default_delete> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(856): message : see reference to function template instantiation 'void std::_List_node_insert_op2<std::allocator<std::_List_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer>>>::_Append_range_unchecked<_Iter,_Iter>(_InIt,const _Sentinel)' being compiled 2> with 2> [ 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Alloc=std::allocator<std::unique_ptr<BleGattService,std::default_delete>>, 2> _Iter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0>, 2> _InIt=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0>, 2> _Sentinel=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(856): message : see reference to function template instantiation 'void std::_List_node_insert_op2<std::allocator<std::_List_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer>>>::_Append_range_unchecked<_Iter,_Iter>(_InIt,const _Sentinel)' being compiled 2> with 2> [ 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Alloc=std::allocator<std::unique_ptr<BleGattService,std::default_delete>>, 2> _Iter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0>, 2> _InIt=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0>, 2> _Sentinel=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(864): message : see reference to function template instantiation 'void std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::_Construct_range_unchecked<std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>>(_Iter,_Iter)' being compiled 2> with 2> [ 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Iter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(864): message : see reference to function template instantiation 'void std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::_Construct_range_unchecked<std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>>(_Iter,_Iter)' being compiled 2> with 2> [ 2> _Ty=std::unique_ptr<BleGattService,std::default_delete>, 2> _Iter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<BleGattService,std::default_delete>>>,std::_Iterator_base0> 2> ] 2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\list(862): message : while compiling class template member function 'std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::list(const std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>> &)' 2>C:\Users\m.chiarappa\source\repos\WinBle-master\src\WinBleLib\BleDevice.h(92): message : see reference to function template instantiation 'std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>::list(const std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>> &)' being compiled 2>C:\Users\m.chiarappa\source\repos\WinBle-master\src\WinBleLib\BleDevice.h(52): message : see reference to class template instantiation 'std::list<std::unique_ptr<BleGattService,std::default_delete>,std::allocator<std::unique_ptr<BleGattService,std::default_delete>>>' being compiled 2>Done building project "WinBleTest.vcxproj" -- FAILED. ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

If I try to compile the code for x64 the result is the same. I left untouched the code.

DerekGn commented 2 years ago

Its an odd one as it is due to the fact that the unique_ptr cannot be copied as it has unique ownership properties.

When targeting Visual Studio 2019 (v142) the code compiles. When targeting Visual Studio 2022 (v143) the code does not compile as it enforces the no copy semantics of the unique_ptr. I am not sure why this is the case as the definition of the unique_ptr is the same in both so it should have broken when I used unique_ptr in the first place. It looks like some compiler differences.

unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;

The simplest solution is to use shared_ptr over unique_ptr as the ownership semantics are not that important or change the coded to use move operations.

I can update the code to use share_ptr but not right now. Maybe in a day or too.

mikechiarappa commented 2 years ago

Hi Derek, I would inform you I have textually replaced all instances on unique_ptr with shared_ptr and now the code is compiled correctly.

DerekGn commented 2 years ago

Hi Mike,

If you like maybe you could open a PR and I can merge the changes into dev branch. If not I can make the changes later today and push to dev

mikechiarappa commented 2 years ago

I've just applied my patches on PR (I hope I haven't made mistakes: 4 files patched) Bye

DerekGn commented 2 years ago

I have merged the PR and have also updated the platform tool set to VS2022 and replaced the remaining unique_ptr references