I'm trying to build my project, which uses things like __cpuid and __cpuidex, so I need intrin.h. When I try to include it and build my project, I get two errors. They are:
`tagMENUBARINFO::fUnused`: type of bit field too small for number of bits
in winuser.h, and in minwindef.h I get the error
`BOOL`: redefinition; different basic types
My includes:
#include <Windows.h>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <intrin.h>
I need all of these includes, so removing some isn't really an option.
I'm using Visual Studio 2019 as my compiler, my Windows SDK Version is 10.0, and the C++ language standard is ISO C++14 Standard.
Related
I was trying to compile an old code, and received the following error:
error G1A4676F8: no member named '__find_end' in namespace 'std'
I searched online and found it is defined in stl_algo.h, which I couldn't find in my Windows system. Also, the documentations were of libstdc++4 and earlier.
The code compiles fine on https://godbolt.org/ with all MSVC versions.
The include statements are:
#include <string>
#include <algorithm>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <stdexcept>
The compiler shows an alternative as find_end defined in algorithm but I am not sure if __find_end has the same functionality as find_end.
So, my question is, is __find_end deprecated?
If not, where can I find it's declaration in Windows?
If yes, what are my alternatives? Is find_end a perfect substitute for __find_end?
I decided to try STL and use a vector instead of a custom made growable array class. The problem is that I can't get anything to compile. If I do something like this:
#include "stdafx.h"
#include <vector>
std::vector<PITEMID_CHILD> APIDL;
I get a bunch of messages similar to this:
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\cstdint(23): error C2039: 'int_least8_t': is not a member of '`global namespace''
If I change to this:
#include <vector>
#include "stdafx.h"
std::vector<PITEMID_CHILD> APIDL;
I get this:
1>x:\win32testing\vectortest\vectortest.cpp(4): error C2039: 'vector': is not a member of 'std'
Inside of stdafx.h is this:
#pragma once
#include <windows.h>
#include "targetver.h"
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <shlobj.h>
#include <exdisp.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <atlbase.h>
#include <atlalloc.h>
#include <CommonControls.h>
// reference additional headers your program requires here
#include <CommCtrl.h>
Any idea what is going on?
From wikipedia documentation:
Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.
The best solution is to get rid of precompiled headers.
And for your C2039 error, it doesn't seem to be a result of line std::vector<PITEMID_CHILD> APIDL;. int_least8_t is a type defined in cstdint (stdint.h). It seems you haven't included this header file in your project.
Whenever I include D3DX11Effect.h in my project, I get hundreds of errors from multiple different DirectX header files that do not give me errors when I do not include D3DX11Effect.h. These are my includes:
#include <string>
#include <dwmapi.h>
#include <iostream>
#include <Windows.h>
#include <vector>
#include <thread>
#include <chrono>
#include <string>
#include <sstream>
#include <TlHelp32.h>
#include <exception>
#include <memory>
#include <vector>
#include <D3D11.h>
#include <d3dx11.h>
#include <DXErr.h>
#include <D3DX11async.h>
#include <D3DX11Effect.h>
#include <D3Dcompiler.h>
#include <D3D11Shader.h>
#include <FW1FontWrapper.h>
#include "../Drawing/ImGUI/imgui.h"
#include "../Drawing/DirectX.h"
#include "../Drawing/imgui_dx11.h"
#include "../Drawing/ShaderFX.h"
#include "../Drawing/Renderer.h"
#include "Global.h"
I'm using Direct X 11 andWindows SDK version 10.0.16299.0. I've tried reinstalling DirectX with no luck. Here is an image of some of the errors I'm getting:
Any help is appreciated.
TL;DR: Read MSDN.
The DirectX SDK is deprecated, and the Windows 8.0 SDK, Windows 8.1 SDK, and Windows 10 SDK headers are newer than the headers that shipped in the legacy DirectX SDK. You are getting a mix of old headers and hew headers, which is why you are getting those errors.
The first thing to consider is if you need to use the legacy DirectX SDK at all. Ideally you just don't use it. This means avoiding the D3DX11 utility library which itself is also deprecated. You can find a number of open source replacements for that functionality listed in the article Living without D3DX, including the latest version of Effects for Dirct3D 11.
You can continue to use the legacy DirectX SDK mixed with modern versions of the Windows SDK, but you need to do it with some care as explained at the bottom of the MSDN page Where is the DirectX SDK?:
VC++ Directory include/lib paths must be in reverse traditional order so you get the newer headers where they conflict
You need to explicitly include d3d11.h and dxgi.h before you include d3dx11.h or you end up with the wrong version--which is exactly what happened above; you are using getting an outdated version of dxgi and/or d3dcommon.
For dxerr.h, build your own version as explained here because (a) it doesn't ship in the Windows SDK, and (b) the version that ships in the legacy DirectX SDK is not fully compatible with modern versions of Visual C++.
Note that the error buried in your image: C2440 static_cast cannot convert from const char[6] to char * in renderer.h has nothing to do with the issue above. This is due to the fact that modern C++11 rules on string literals disallow using them as non-const. You should fix the code, but you can also turn off strictstrings if you don't care about portability/conformance. In any case, take some time to read up on const correctness.
See The Zombie DirectX SDK for a complete dissection of what headers conflict, which ones are unique to the DirectX SDK, and which ones have any value for DirectX 11 games on modern versions of Windows.
You should review the various posts I've made in the past 8 years on this subject as well.
I can litterally not find which library/header this function is in, I've looked at so many examples of people using this function, but there are no results...
These are all the stuff I've included:
#include "Console.h"
#include "Direct3D9.h"
#include <string>
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
But still strtof comes up as "Error namespace "std" has no member "strtof""
What I'm trying to do:
flValue = std::strtof( vszArgs.at( 1 ).c_str( ), NULL );
pConVar->Set( flValue );
Visual Studio 2012 does not implement strtof.
Link to MSDN bug report which includes a suggested workaround.
You can find it in cstdlib when using C++11. The information can easily be found here : http://www.cplusplus.com/reference/cstdlib/strtof/?kw=strtof
My guess is that you aren't compiling using c++11.
1) Include stdlib.h
#include <stdlib.h> /* strtof */
from http://www.cplusplus.com/reference/cstdlib/strtof/
If that still doesn't work...
2) Make sure your compiler is C++11 or newer
It's new as of C++11 so if you have an older compiler it won't work.
If that still doesn't work...
3) Your compiler may just not support it
Visual C++ 2012 does not have full support for the C++11 standard. See the Visual Studio bug "Missing strtof, strtold, strtoll, strtoull functions from stdlib.h".
We don't yet have those functions in the CRT. We will consider adding them to a future version of Visual C++.
There's nothing fancy going on in this program, but I get garbage output. Here are the header files I'm including, in case that's relevant.
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <vector>
#include <string>
#include <sstream>
And I'm using Visual Studio 2008 on Windows XP.
Note that if I print the string to stdout, it prints "test" perfectly fine.
Sometimes the debugger will have trouble picking up proper values if you've compiled in Release mode. The compiler might swap around operations or move values to registers, etc.