Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] Mingw Windows compilation GetPhysicallyInstalledSystemMemory Error #976

Open
RealVarHar opened this issue Dec 23, 2024 · 1 comment

Comments

@RealVarHar
Copy link

Hi,
Im using windows, mingw, gcc/clang from winlibs.com to be exact.
Ive noticed that on my machine
main branch was building,
but dev was not building,
due to error call to undeclared function 'GetPhysicallyInstalledSystemMemory';
Please replace CMakeLists.txt line
if(MINGW)
add_definitions(-D_WIN32_WINNT=0x600)
endif()

with

if(MINGW)
add_definitions(-D_WIN32_WINNT=0x601)
endif()

as mingw has a bit different legacy settings and treats this function as avaliable since win7, not Vista.
This >>should<< not break anything with other ways of windows builds, in the worst case it will abandon Vista support
(Apologies this is not a Pull request)

@imsharukh1994
Copy link

Modify CMakeLists.txt
Open your CMakeLists.txt file: This file should be in the root directory of your project. It contains the build configuration for your project, including platform-specific settings.

Find the block that checks for MinGW: Look for a section in CMakeLists.txt that looks like this:

cmake
Copy code
if(MINGW)
add_definitions(-D_WIN32_WINNT=0x600)
endif()
This block sets the minimum Windows version to Windows Vista (0x600). The issue arises because the function GetPhysicallyInstalledSystemMemory is only available in Windows 7 and later, so you need to update the version check.

Update the _WIN32_WINNT value: Modify the value from 0x600 (Vista) to 0x601 (Windows 7). The updated block should look like this:

cmake
Copy code
if(MINGW)
add_definitions(-D_WIN32_WINNT=0x601)
endif()
This tells the compiler that the minimum supported Windows version is Windows 7, which will make the GetPhysicallyInstalledSystemMemory function available during the build.

Save the file: After making the change, save the CMakeLists.txt file.

Rebuild your project: Run your build process again (for example, using cmake and make or through an IDE like CLion or Visual Studio Code). This should resolve the error related to the undeclared function.

Why this works:
What _WIN32_WINNT=0x601 means:

The macro _WIN32_WINNT defines the minimum version of Windows that your application supports.
0x600 corresponds to Windows Vista.
0x601 corresponds to Windows 7.
By setting _WIN32_WINNT=0x601, you're telling the compiler that you're targeting at least Windows 7, where the GetPhysicallyInstalledSystemMemory function is available.

Impact:

This change will not affect any other builds targeting newer Windows versions (like Windows 8, 10, or 11), as they support this version of the Windows API.
The only downside is that your project will no longer support Windows Vista. However, Windows Vista has reached its end of life, and most modern software no longer targets it.
Conclusion:
Open CMakeLists.txt.
Modify the if(MINGW) block to use 0x601 instead of 0x600 for _WIN32_WINNT.
Save the file and rebuild the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants