D_WIN32_WINNT compiler warning with Boost
Asked Answered
W

7

37

Not sure what to make of this error. Added -D_WIN32_WINNT=0x0501 to Visual Studio's "Command Line" options under Project Properties but it says it doesn't recognize it and the warning still appears.

I am also not sure how to add the Preprocessor Definition.

1>Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1>- add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1>- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.

Woe answered 8/6, 2010 at 18:38 Comment(0)
H
24

I think you're really close to getting this to work. John Dibling gave three ways you could do this and it looks like you tried the third solution, which was to "go in to your project's settings ... and under the Configuration Properties->C/C++->PreProcessor heading, add ;_WIN32_WINNT = 0x0501". You replied that you were still getting that error and provided the contents of your preprocessor settings, WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT = 0x0501. I think you can solve this if you change _WIN32_WINNT = 0x0501 to _WIN32_WINNT=0x0501. When I tried the version with spaces, it did not eliminate the error, but removing the spaces did.

Humfrey answered 17/9, 2010 at 20:46 Comment(1)
Manually defining these compile definitions is a bad idea. See Hill's answer.Pious
C
34

Add following line in your top source code.

#include <SDKDDKVer.h>
Chrysler answered 7/5, 2017 at 14:10 Comment(3)
This will work but would this be a code smell to have an include statement for no real functionality but to just get rid of a compiler warning when this could be edited in the build properties instead? Just a thought. I'm currently using this as the answer right now in development for a trivial project.Koon
Using the actual version from the actual SDK seems to be the right way as opposed to select some target almost randomly.Chevrotain
This seems like the proper fix indeed.Defibrillator
H
24

I think you're really close to getting this to work. John Dibling gave three ways you could do this and it looks like you tried the third solution, which was to "go in to your project's settings ... and under the Configuration Properties->C/C++->PreProcessor heading, add ;_WIN32_WINNT = 0x0501". You replied that you were still getting that error and provided the contents of your preprocessor settings, WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT = 0x0501. I think you can solve this if you change _WIN32_WINNT = 0x0501 to _WIN32_WINNT=0x0501. When I tried the version with spaces, it did not eliminate the error, but removing the spaces did.

Humfrey answered 17/9, 2010 at 20:46 Comment(1)
Manually defining these compile definitions is a bad idea. See Hill's answer.Pious
I
21

A few options.

1) If you have a main header file, like stdafx.h, you could add this:

#define _WIN32_WINNT 0x0501

Or you could add that anywhere you need it.

2) You can add -D _WIN32_WINNT=0x0501 (note the space)

3) Go to Project Properties > Configuration Properties > C/C++ > Proporcessor. Add ;_WIN32_WINNT=0x0501 to Preprocessor Definitions.

Personally, I choose #3 because there's no doubt about it being defined at the right time in the right translation units, and I'd rather have all the #defines in one place rather than some being in Preprocessor Defines and others in the advanced tab.

Invention answered 8/6, 2010 at 21:2 Comment(6)
Below is an exact paste of what is in my #3). Still getting that error. :( WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT = 0x0501Woe
and @bobber205: in option #3 don't put spaces around the equals sign in the Preprocessor definitions lineJeromejeromy
just a minor typo: #define _WIN32_WINNT = 0x0501 is not correct, remove the "=" symbol. This is correct: #define _WIN32_WINNT 0x0501Indigestive
@Dredok: thx, edited. BTW, feel free to make edits like these yourself.Invention
I found a solution which may work for you also, add this to your API project: #include <SDKDDKVer.h> //Allows Boost compilation in module to select the correct compilation targetAbbevillian
More details on specifying the minimum operating system can be found here: learn.microsoft.com/en-us/cpp/porting/…Prang
W
3

Put a space after the D

Wini answered 8/6, 2010 at 19:34 Comment(0)
G
2

You should define the WIndow sversion you ant to target as many have suggested:

// Target Windows XP
#define _WIN32_WINNT 0x0501

The reasons you do not want to use the SDK version that happens to be installed are:

  • To have reproducible builds. You don't want to just pick up whatever happens to be installed as that can very for each person trying to build.
  • To be in control of your target platform. You don't want to target Windows 11 just because you happen to compile on Windows 11. As the programmer, you want to be in control of what is done.
  • To support the widest range of Windows versions. Users will be grateful that they can run your program on their older Windows version.
Gazette answered 5/6, 2022 at 20:53 Comment(0)
M
2

OP didn't ask about CMake, but google brought me here. If you're using CMake, try adding this to your (top-level) CMakeLists.txt:

if (WIN32)
  add_definitions(-D_WIN32_WINNT=<myWindowsTarget>)
endif()

I was interested in Windows 10, so myWindowsTarget was 0x0A00. Here's a full list of Windows Targets

Manofwar answered 11/12, 2022 at 6:38 Comment(1)
This resolved my issue. I was building the boost libraries with the specified target but didn't add it in CMakeLists.txt, and it consistently failed the build.Allysonalma
E
0

For Code Blocks here is how you do it.

Right click **Project Name** on your left >> Click 'Build Options' >> Select Debug or Release on your left >> Select 'Compiler Settings' Tab on the right >> Select #defines tab >> Then add the following line as it is:

_WIN32_WINNT=0x0501

>> Click Ok >> Close >> Right click **Project Name** again >> Re-build.
Eleven answered 26/6, 2017 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.