glut.h error when testing glut in code blocks - c++

When trying to build a project using glut I get an error. Not in the main.cpp but rather in the glut.h I've included.
#pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */
#pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */
#pragma comment (lib, "glu32.lib") /* link with OpenGL Utility lib */
#pragma comment (lib, "glut32.lib") /* link with Win32 GLUT lib */
#pragma warning (disable:4244) /* Disable bogus conversion warnings. */
#pragma warning (disable:4305) /* VC++ 5.0 version of above warning. */
All of these lines are the ones who show an error with the description:
Warning: ignoring #pragma warning [-Wunkown-pragmas]
It's the same error for all of the these lines.
I also get one additional error, also in the glut.h file. It's on the line:
typedef unsigned short wchar_t;
This error reads:
error: redeclaration of built in C++ type "wchar-t" [-fpermissive]
Anyone who's got an idea of how I should go about solving this issue.
The linking seems to be fine since it realizes that the glut.h file
exist but the glut.h is the file providing the errors.

Related

DirectX 11 and g++ compile error

Hello I actually learning DirectX 11 with this tutorial: http://www.rastertek.com/dx11tut03.html
First Part
My code (where the probleme come from):
d3dclass.h:
//Linking
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
//Include
#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <d3dx10math.h>
I do all like the tutorial, the only diference is I compile it with g++, trough this the command :
g++ -mwindows WinMain.cpp systemclass.cpp inputclass.cpp graphicsclass.cpp d3dclass.cpp -o Prog.exe -I "D:\Programme File\DirectX SDK\Include" 2> log.txt
but in the output file, I have a large sum of errors. This is the log.txt:
https://drive.google.com/open?id=1XUlcAFUyRcLIvdKbe0FkLVjkvwxpOmEv
To sum up the log there is a lot of things like __in which has not been declared in the dxgi.h, but this header is from DirectX11 Library;
Second Part
I found the way to fix a lot of my problem (of the first part) with adding this :
#define __in
#define __out
#define __inout
#define __in_bcount(x)
#define __out_bcount(x)
#define __in_ecount(x)
#define __out_ecount(x)
#define __in_ecount_opt(x)
#define __out_ecount_opt(x)
#define __in_bcount_opt(x)
#define __out_bcount_opt(x)
#define __in_opt
#define __inout_opt
#define __out_opt
#define __out_ecount_part_opt(x,y)
#define __deref_out
#define __deref_out_opt
#define __RPC__deref_out
but there still is a major problem, this is the error output :
D:\Programme File\DirectX SDK\Include/d3dx10core.h:345:13: error: expected ';' at end of member declaration
HRESULT WINAPI_INLINE GetDesc(D3DX10_FONT_DESCA *pDesc) { return GetDescA(pDesc); }
it comes from WINAPI_INLINE (this is in the DirectX header)
How can I fix this? please.
I don't have any experience with using g++, but I can help with a few details here. To use g++ you need to install the Windows SDK and configure it to include the proper paths. The legacy DirectX SDK requires the Windows SDK and is not fully standalone.
Note that the legacy DirectX SDK and the Windows SDK don't claim to be compatible with the GCC toolchain.
The __in, __out, etc. macros are called "SAL annotations" and they are there to improve the quality of static code analysis both internally at Microsoft and when using Visual C++'s /analyze switch. They are defined as 'blank' in other cases so they just get removed from the code. The macros are defined in the Windows SDK. You can try explicitly doing a #include <sal.h> and/or #include <specstrings.h> before including a version of dxgi.h.
Another thing to keep in mind is that the legacy DirectX SDK itself is deprecated along with the D3DX9, D3DX10, and D3DX1 utility libraries. As such, if you are using the Windows 8.0, 8.1, or 10 SDK you can code Direct3D 11 without using it at all--see Living without D3DX. If you do want to continue to use those older helpers--which the somewhat dated rastertek tutorials assume--, you can do so but you need to make sure the DirectX SDK include and lib paths are searched after the Windows SDK include/lib paths.
If you were using Visual C++ (which BTW has a free Community edition available), then you'd probably be having an easier time. You might also want to see the DirectX Tool Kit tutorials.

defining pragmas in a freeglut programme

I am building an application that uses freeglut, in windows 32bit, debug mode. I have linked the static debug freeglut lib.
To fix linkage errors, as mentioned here:
freeglut error LNK1104
I have added:
#define FREEGLUT_STATIC
#define _LIB
#define FREEGLUT_LIB_PRAGMAS = 1
to the head of my .cpp.
That solves the linkage errors, but gives me an error in the freeglut_std.h file.
These sections:
# if FREEGLUT_LIB_PRAGMAS
# pragma comment (lib, "freeglut_static.lib")
# endif
# if FREEGLUT_LIB_PRAGMAS
# pragma comment (lib, "glu32.lib") /* link OpenGL Utility lib */
# pragma comment (lib, "opengl32.lib") /* link Microsoft OpenGL lib */
# pragma comment (lib, "gdi32.lib") /* link Windows GDI lib */
# pragma comment (lib, "winmm.lib") /* link Windows MultiMedia lib */
# pragma comment (lib, "user32.lib") /* link Windows user lib */
# endif
give me:
Error 3 error C1017: invalid integer constant expression freeglut_std.h 72 1
4 IntelliSense: expected an expression freeglut_std.h 72 12
Where am I going wrong here?
Thank you.

LINKER error: comsupp.lib and comsuppwd.lib

error is:
Error 14 error LNK2005: "void __stdcall _set_com_error_handler(void (__stdcall*)(long,struct IErrorInfo *))" (?_set_com_error_handler##YGXP6GXJPAUIErrorInfo###Z#Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Did anyone run into this before?
There is a bug in the Visual Studio 2010 header <msclr/marshal.h>.
There is written
#pragma comment(lib, "comsupp.lib")
but compared to <comdef.h> there must be written
#ifdef _NATIVE_WCHAR_T_DEFINED
# ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
# else
# pragma comment(lib, "comsuppw.lib")
# endif
#else
# ifdef _DEBUG
# pragma comment(lib, "comsuppd.lib")
# else
# pragma comment(lib, "comsupp.lib")
# endif
#endif
See also the Lib-section in https://learn.microsoft.com/de-de/cpp/cpp/set-com-error-handler?view=vs-2019
So you have 2 Options
BAD: Edit the msclr/marshal.h in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\msclr\marshal.h. But then all collegues must change their file too.
Change the ProjectSetting Linker -> Input -> Ignore Specific Default Libraries and add commsupp.lib. !!!But attention if you have set the compiler option /Zc: wchar_t- (see C/C++ -> Language -> Treat WChar_t as Built in Type) AND compiling for Release then it must not be ignored!!! So each project configuration may/must be changed differently.
Error is resolved now. The cause of error was a header file: #include <msclr\marshal_cppstd.h> and conversion from System::String^ to std::string(I found a similar issue here):
//commented out following 3 lines and problem solved:
//looks like following type conversion has problems:
#include <msclr\marshal_cppstd.h>
msclr::interop::marshal_context marshal_context_1;
string_TempDir_XMLfiles=marshal_context_1.marshal_as<std::string>(String_Ptr_Destin_Dir_XMLfiles);

How to turn on GDI+ 1.1 instead of 1.0 in MFC project?

I unable to use GDI+ 1.1 classes in my VS2012 MFC C++ project (on Win7). Classes Image, Bitmap, Graphics works just fine but when I try to declare an object of Blur class (or other v1.1 classes) I am getting an error C2065: ‘Blur’: undeclared identifier. I tried to define GDIPVER (in stdafx.h) like this
#define GDIPVER 0x0110 //also I get the warning C4005: 'GDIPVER' : macro redefinition
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")
but it does not work.
How to turn on GDI+ 1.1 instead of 1.0?
I fought with a similar issue for a while on one project. For me, my precompiled header has this:
#define GDIPVER 0x0110 // Use more advanced GDI+ features
but the precompiled header does not #include "gdiplus.h". That only occurs in the .cpp files which actually make GDI+ calls. I forward declare GDI+ classes for the headers which have GDI+ object pointers as members. As Hans and other comments noted, there's probably another header including gdiplus.h before the GDIPVER is set. To figure out where it's included try going to the C/C++ > Command Line settings for your project and add /showIncludes then do a full build and look in the build log for gdiplus.h and track back to the first header including it.
Once you clear that hurdle, I also discovered my application would not actually use the 1.1 features unless the manifest was also updated. So one of my .cpp files has this:
// Update Manifest
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx
//
// We use features from GDI+ v1.1 which is new as of Windows Vista. There is no redistributable for Windows XP.
// This adds information to the .exe manifest to force GDI+ 1.1 version of gdiplus.dll to be loaded on Vista
// without this, Vista defaults to loading version 1.0 and our application will fail to launch with missing entry points.
#if 64BIT_BUILD
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
FWIW, I did the following to enable GDI+ 1.1 in a VS 2019 MFC project:
Added this line in pch.cpp before including pch.h:#define GDIPVER 0x0110
Added these lines in pch.h after including framework.h:#include <gdiplus.h>using namespace Gdiplus;
Used a slightly modified and updated version of the code block kindly provided by #jschroedl 7 (!) years ago:
// Update Manifest
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx
//
// We use features from GDI+ v1.1 which was new as of Windows Vista. There is no redistributable for Windows XP.
// This adds information to the .exe manifest to force the GDI+ 1.1 version of gdiplus.dll to be loaded.
// Without this, Windows will load the GDI+ 1.0 version of gdiplus.dll and the application will fail to launch with missing entry points.
#ifdef _WIN64
//#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
//#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
I instantiated a Blur object in my startup code to verify I was compiling against GDI+ 1.1 and scoping it so it would be destroyed before calling GdiplusShutdown(), and the app ran and shut down correctly in both x86 and x64 builds.

What is the best solution for suppressing warning from a MS include (C4201 in mmsystem.h)

I am tired of having to look at warnings during our compilations - warnings that come from MS include files.
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\mmsystem.h(1840): warning C4201: nonstandard extension used : nameless struct/union"
I have seen this thread that suggests changing the header itself (but then each of my team mates has to do it and we have to do it on the build server - not to mention it is a glorious HACK)
Is there a better way? I don't want to turn it off globally - just to suppress it for certain files or directories.
Any suggestions?
EDIT
For some stupid reason I didn't think I could set warning levels across include files. Thanks - that does the trick.
Something like
#pragma warning(push, disable: 4201)
#include <mmsystem.h>
#pragma warning(pop)
How about using #pragma warning extension in VC++?
http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
#pragma warning (push, 2) // Temporarily setting warning level 2
#include <mmsystem.h>
#pragma warning (pop) // Restore back
You may also try ..
#pragma warning (disable: 4201)
#include <mmsystem.h>
#pragma warning (default)
With VS 2017 Community, to avoid warning C4083, I use :
#pragma warning(push)
#pragma warning(disable:4201)
#include <dxvahd.h>
#pragma warning(pop)