28

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.

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
bobber205
  • 11,636
  • 25
  • 71
  • 97

5 Answers5

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.

foven
  • 658
  • 1
  • 5
  • 15
  • Manually defining these compile definitions is a bad idea. See Hill's answer. –  Oct 26 '20 at 11:57
19

Add following line in your top source code.

#include <SDKDDKVer.h>
Hill
  • 2,522
  • 3
  • 18
  • 26
  • 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. – DtechNet Jan 09 '19 at 19:19
  • 3
    Using the actual version from the actual SDK seems to be the right way as opposed to select some target almost randomly. – dabadab Mar 27 '19 at 15:45
  • 3
    This seems like the proper fix indeed. – François Beaune Jul 18 '19 at 15:23
17

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.

cambunctious
  • 4,860
  • 3
  • 22
  • 35
John Dibling
  • 94,084
  • 27
  • 171
  • 303
  • Below is an exact paste of what is in my #3). Still getting that error. :( WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT = 0x0501 – bobber205 Jun 09 '10 at 00:50
  • 2
    and @bobber205: in option #3 don't put spaces around the equals sign in the Preprocessor definitions line – Eli Bendersky Feb 23 '11 at 12:48
  • just a minor typo: #define _WIN32_WINNT = 0x0501 is not correct, remove the "=" symbol. This is correct: #define _WIN32_WINNT 0x0501 – Dredok Jul 14 '15 at 08:52
  • @Dredok: thx, edited. BTW, feel free to make edits like these yourself. – John Dibling Jul 14 '15 at 19:16
  • I found a solution which may work for you also, add this to your API project: #include //Allows Boost compilation in module to select the correct compilation target – Jamie Nicholl-Shelley Feb 13 '20 at 22:44
3

Put a space after the D

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
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.
Saurabh Bhandari
  • 2,300
  • 4
  • 24
  • 30
Bonga the Poo
  • 121
  • 1
  • 4