D_WIN32_WINNT compiler warning with Boost - c++

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.

Add following line in your top source code.
#include <SDKDDKVer.h>

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.

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.

Put a space after the D

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.

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.

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

Related

How to set the correct Intellisense configuration for include path in VS Code?

I am trying to work with Emscripten. I have the compiler set up and working and now I'd like to write some code.
However, the include for emscripten remains underlined in red and I can see this error:
#include <emscripten/emscripten.h>
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (D:\MYPROJECT\cpp\main.cpp).C/C++(1696)
cannot open source file "emscripten/emscripten.h"C/C++(1696)
A "Quick fix" (quotes intended) takes me to the Microsoft C/C++ Extension - IntelliSense Configurations. And there I can edit include paths. I have created a new configuration named EMSCRIPTEN and set these paths:
${workspaceFolder}/cpp/**
D:\lib\emsdk\upstream\emscripten\system\include
But this has no effect. Now if I do add this to the default configuration that was there from the start (Win32), it works. But I don't want to use that one for my emscripten project! I was kinda hoping to convince to IDE to compile my programs as well.
So how do I set per-workspace C++ compiler settings to a given configuration?
Ok, I found it, it's to the right bottom of the screen next to language type selection:

visual studio solution configuration value in C++

I would like to know if there is a way to get the solution configuration name (debug, release, etc) in the program maybe in a #define ?
I found on the forum this post but the litle function doesn't work for me.
Thanks a lot
Use YOUR_FANCY_NAME="$(ConfigurationName)" in [Configuration Properties] -> [C/C++] -> [Preprocessor] -> [Preprocessor Definitions].
If you don't need the exact name and only want to determine if the current build is a debug build, you can use the preprocessor define _DEBUG:
#ifdef _DEBUG
// stuff
#endif

unique_ptr autocomplete in eclipse

I am playing with unique_ptr. In my last post people helped me compiling a program that used this pointer by specifying the -std=c++0x during compilation.
Now i was wondering if there is any way to instruct eclipse to consider c++11 while auto-completing?
unique_ptr is not coming in the list of std:: namespace, nor I can find the methods (reset, move...) associated with a unique_ptr.
Thank you
vahid
The "memory" header (probably found at /usr/include/c++/4.9/memory) only includes "unique_ptr.h" and "shared_ptr.h" (probably found at /usr/include/c++/4.9/bits/unique_ptr.h and /usr/include/c++/4.9/bits/shared_ptr.h) if the macro "__cplusplus" is equal or greather than "201103L". Check memory.h for yourself to see the "#if" preprocessor condition there, at line 69 (or search for the string "#if __cplusplus >= 201103L").
As others mentioned, compiling with "-std=c++0x" or later c++ standards (-std=c++11 or -std=c++14) solves the compilation errors, but not the eclipse indexing and autocomplete problem.
To solve the eclipse indexing issue I added the "__cplusplus" Preprocessor Macro to the project build properties, with the value "201103L", and afterwards I refreshed the index;
To add the preprocessor macro:
"right click the project on project explorer" >> properties >> C/C++ General >> Preprocessor Includes >> Entries >> GNU C++ >> CDT User Settings Entries >> Add... >> Preprocessor Macro;
Then entry a macro with name "__cplusplus" and value "201103L";
Afterwards, to refresh the index, do:
"right click project on project explorer" >> Index >> Rebuild;
Ps.: I was using gcc 4.9.2 and eclipse Luna (4.4.2), on ubuntu 15.04 64bits
I guess you should add __GXX_EXPERIMENTAL_CXX0X__ definition to your "Paths and Symbols" in Eclipse. See also this question GNU C++ how to check when -std=c++0x is in effect? and the same question Eclipse indexer can't resolve shared_ptr for shared_ptr.

How to set predefined macros in Code::Blocks

Is there a way to set some predefined Macros for my local installation of Code::Blocks.
To elaborate on that, basically I would like to have certain blocks compiled only at pc and not anyplace I send the code to. One way to achieve this is as follows:
#define MYPC
#ifdef MYPC
//do something
#else
// do something else
#endif
I was to achieve the same thing, but I don't want to include the line #define MYPC and woud like to add this somewhere in the IDE. I know how to do this in Visual Studio, and I think it also exists in Code::Blocks as well.
Thanks.
Project - Properties - Project's build options - Compiler Settings - #defines.
Edit. Example of #defines edit box:
CONSTANT1
CONSTANT2="0"
Gives the following command line:
g++ -DCONSTANT1 -DCONSTANT2="0" ...

Strange compiler errors with code::blocks

I switched from Visual Studio to Code::Blocks yesterday, and just had some strange compiler error messages.
I included windows.h and i can use all the API calls just fine, such as creating window classes and creating windows / buttons and stuff. But when I tried to send some keypresses with SendInput(), I got error messages on these two declarations:
INPUT ip;
KEYBDINPUT kbi;
Compiler errors:
C:\code_blocks\test-app\main.cpp|21|error: 'INPUT' was not declared in this scope|
C:\code_blocks\test-app\main.cpp|22|error: 'KEYBDINPUT' was not declared in this scope|
I can even right click the KEYBDINPUT and INPUT structors and click on "Find declaration", it finds it inside the "winuser.h" (which is inside ), but it's still giving me these error messages that they are not declared.
This code works fine in VS with just windows.h included. I'm using the GNU GCC compiler.
I think you need the pre-processor directives (Visual Studio may already add them):
What do you have _WIN32_WINNT defined as?
Perhaps you could add:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
or you can add it to your pre-processor directives as part of your compile sequence. Any good compiler will have it.
If it still doesn't work, remove the include guards and define it directly. Maybe it is getting defined elsewhere.
Some compilers will have this in the pre-processor directive settings: WIN32,_DEBUG,_CONSOLE,_MBCS,_WIN32_WINNT=0x0400
To elaborate on Changeling's answer, if you look at the documentation for say KEYBDINPUT, you will see that near the bottom it has a table of minimal supported OS versions. VC++ sets _WIN32_WINNT to a later version than MinGW/GCC (which I am guessing is the compiler you are using with Code::Blocks), which is probably why you have encountered this problem.
The purpose of this macro is to prevent you inadvertently using API's that are not compatible with your minimum intended target OS.
There are a number of version related macros used by Windows API headers. The details can be found here