lfreist / hwinfo

cross platform C++ library for hardware information (CPU, RAM, GPU, ...)
MIT License
438 stars 76 forks source link

MinGW-w64 failed: error: cast from 'BSTR {aka wchar_t*}' to 'int' #30

Closed pigLoveRabbit520 closed 1 year ago

pigLoveRabbit520 commented 1 year ago
D:/mini_tool/third_party/hwinfo/include/hwinfo/WMIwrapper.h:91:23: error: cast from 'BSTR {aka wchar_t*}' to 'int' loses precision [-fpermissive]
       value.push_back((T)((bstr_t)vtProp.bstrVal).copy());
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make32[2]: *** [third_party\hwinfo\src\CMakeFiles\HWinfo.dir\build.make:406: third_party/hwinfo/src/CMakeFiles/HWinfo.dir/windows/cpu.cpp.obj] Error 1
make32[1]: *** [CMakeFiles\Makefile2:140: third_party/hwinfo/src/CMakeFiles/HWinfo.dir/all] Error 2
make32: *** [Makefile:90: all] Error 2
lfreist commented 1 year ago

Hi, could you please provide the full error stack?

Also could you built the example project?

pigLoveRabbit520 commented 1 year ago

OS: windows 10 MinGW-W64 version: gcc version 7.3.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)

step

git clone https://github.com/lfreist/hwinfo
mkdir build
cd build
cmake -G "Unix Makefiles" .. 
make

and got the error:

C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h: In instantiation of 'bool hwinfo::wmi::queryWMI(const string&, std::__cxx11::string, std::vector<T>&, const string&) [with T = const wchar_t*; std::__cxx11::string = std::__cxx11::basic_string<char>]':
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/src/windows/cpu.cpp:31:58:   required from here
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h:79:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       value.push_back((T)vtProp.intVal);
                       ^~~~~~~~~~~~~~~~
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h:81:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       value.push_back((T)vtProp.boolVal);
                       ^~~~~~~~~~~~~~~~~
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h:83:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       value.push_back((T)vtProp.uintVal);
                       ^~~~~~~~~~~~~~~~~
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h:85:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       value.push_back((T)vtProp.uiVal);
                       ^~~~~~~~~~~~~~~
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h: In instantiation of 'bool hwinfo::wmi::queryWMI(const string&, std::__cxx11::string, std::vector<T>&, const string&) [with T = int; std::__cxx11::string = std::__cxx11::basic_string<char>]':
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/src/windows/cpu.cpp:93:58:   required from here
C:/Users/WDAGUtilityAccount/Downloads/hwinfo-main/include/hwinfo/WMIwrapper.h:91:23: error: cast from 'BSTR {aka wchar_t*}' to 'int' loses precision [-fpermissive]
       value.push_back((T)((bstr_t)vtProp.bstrVal).copy());
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [src/CMakeFiles/HWinfo.dir/build.make:407: src/CMakeFiles/HWinfo.dir/windows/cpu.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:134: src/CMakeFiles/HWinfo.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
lfreist commented 1 year ago

Thank you! I will debug the issue as soon as possible. Since I have a submission next week, this might takes some time...

facug91 commented 1 year ago

This library requires C++17, and gcc 7 doesn't support it. Can you upgrade it to gcc 8 or greater?

pigLoveRabbit520 commented 1 year ago

@facug91 gcc 8 still got the same error

facug91 commented 1 year ago

Then it seems to be a problem in Windows with the conversion performed in WMIwapper.h. At the moment, I don't have a Windows machine to test it, so I can't fix it either.

pigLoveRabbit520 commented 1 year ago

@facug91 yeah, MinGW-w64 doesn't work well with WMI, it's an old problem.

lfreist commented 1 year ago

@pigLoveRabbit520, I have fixed the MinGW build. Some of the WMI stuff does not work properly and the HWinfo library returns <unknown> or similar. However, it builds and runs the example successfully.

I will further debug the MinGW build. However, I hope it is working for you for now.

Please let me know, (if something)/whats missing for you.