C++ SDL (Visual Studio 2015): cannot open file stddef.h - c++

I'm relatively new to c++ and have been following the Lazy Foo' tutorial for installing SDL2 in visual studio 2010 (But I am using visual studio 2015).
I have followed the guide a couple of times now, so pretty certain I have incuded the right files etc. Here is a screen shot of my VC++ Directories settings:
#include <SDL.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window = 0;
window = SDL_CreateWindow("SDL window",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480,
SDL_WINDOW_SHOWN);
SDL_Delay(1000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
When compiled (32 bit) I receive this error:
......\documents\sdl\sdl2-2.0.4\include\sdl_stdinc.h(50): fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
I also have the error "cannot open source file stdio.h" when hovering over the include statement for stdio.h
I'm going to continue to look at it all, but if anyone has any suggestions that would be greatly appreciated. Failing that I'll probably just install on Linux :)
Cheers and thanks for your time.

Suggestions: Use the dropdown, (inherit from parent or project defaults) to repair the visual c++ directories which you shouldn't ever edit.
Don't add it to the c++ directories, That's a weird idea. Add it to Configuration Properties > c/c++ > additional include directories. If you had done that, then you couldn't have possibly messed up the compiler. It's a lot simpler too. Just paste the one directory in there. That's what it's meant for.
Also Lazy Foo seems to only to have a VS2010 guide. Maybe I just couldn't find the VS2015 guide...

The error message
fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
tends to happen when you're building your program with a version of MSVC different from the one used to build the library.
You should find out which version the SDL binaries were built with, and try using that. A newer MSVC might work, an older one might not.
You can always try building SDL yourself.

Related

sdl, sdl2 error: SDL_window (among others) not declared

I have played around with C++ for a while and just recently started to get into SDL and SDL2.
I was able to get the dot demo program to work.
But other programs, such as Lazy Foo' Productions's copied and pasted don't seem to work.
I have both SDL and SDL2 installed (and uninstalled and reinstalled.) I am on Ubuntu 15.04 and I have the IDE CodeBlocks linked (-ISDL2)
The errors are SDL_Window - SDL_WINDOWPOS_UNDEFINED - SDL_WINDOW_SHOWN - SDL_CreateWindow - SDL_GetWindowSurface - SDL_UpdateWindowSurface and finally, SDL_DestroyWindow -- was not declared in this scope.
Also, I include:
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
I'm pretty sure that I don't need all of that location, but it didn't work without it either. One other note, when I type the #includes, CodeBlocks will suggest SDL2/SDL.h but not SDL/SDL.h.
What am I missing?
I don't think I can put Lazy Foo' code here - I didn't get permission...
The code you listed;
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
Why don't you change it to
#include <SDL2/SDL.h>
#include <stdio.h>
as the first header is where SDL_CreateWindow and other SDL2 functions are declared?
Also you don't need to include both SDL and SDL2 headers. Indeed that could very well be the source of your problem as you would only need to include the version you're using.
If you're following the tutorials from lazyfoo's site, you can check if the ones you're following are using SDL1.2 or SDL2 from their table of contents, as the site actually have the tutorials for both versions.
UPDATE:
I didn't notice that your platform is a Linux platform. Then it is so much easier to solve your problem. The demo that you followed previously was done using SDL-1.2, whereas the gcc error hinted that you're using SDL-2.0, hence SDL_CreateWindow and other undefined errors. You should install SDL-2.0 library and SDL-2.0 development files (which will provide you with the necessary SDL-2.0 headers). You may refer this to SDL-2.0 packages provided by your platform distribution.
As for the compilation, it'll be the same as the tutorial you've followed with a minor change, instead of gcc sdltest.o -lSDL -o sdltest, you'll issue gcc sdltest.o -lSDL2 -o sdltest to indicate that you're linking your code against SDL2 library.
EDIT
A simple SDL program to test your environment. You can use any of the simpler text editor such as nano or gedit or others to edit this, and run the compilation command above to test your setup.
The simplest way to do this is by copy the code, then from your terminal, issue cat > sdltest.cpp and paste the code, then hit [ENTER] and [CTRL-C] to end it. Then you can issue the compilation command as mentioned previously,g++ sdltest.cpp -lSDL2 -o sdltest.
Code;
#include <SDL2/SDL.h>
#include <stdio.h>
int main()
{
SDL_Window *p;
SDL_Renderer *w;
p = SDL_CreateWindow("Game",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,800,640,SDL_WINDOW_SHOWN);
w = SDL_CreateRenderer(p, -1, 0);
SDL_RenderClear(w);
SDL_SetRenderDrawColor(w,255,0,0,255);
SDL_Rect Rect = {220,140,200,200};
SDL_RenderFillRect(w,&Rect);
SDL_RenderPresent(w);
SDL_Delay(3000);
SDL_DestroyRenderer(w);
SDL_DestroyWindow(p);
SDL_Quit();
return 0;
}
Hope that helps.

Error accessing GStreamer Library in Qt C++ - Program excited with code 0xc0000135 when Debugging

I want to use gstreamer library for video programming and I read that Qt5.5.0 provided support for gstreamer-1.0, which is the library I use. I downloaded firstly version 1.0.7, but I got the following error, so I downloaded the latest version 1.5.2, which I am trying to use now.
I managed to link the gstreamer library header files, so I didn't build it, but just include its path and access the header files and libs. Anyway, now I have an error of The program has unexpectedly finished. When I try to debug it, I get the following error in a pop-up:
During startup program excited with code 0xc0000135.
On General Messages:
:1:24: Reading only version 1.1 parts.
:10:5: Expected only Component and ModuleApi object definitions.
I read many questions related to this error, but none helped, I think is an error with the gstreamer library, but may be a compiler/debugger error too, as I read in some threads.
I checked my PATH variable, as I also can not run the program outside Qt (by trying to run the .exe in debug folder of the build) - the error : library Qt5Cored.dll missing - and I found this paths:
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\lib;
C:\Users\user\Documents\build-GStreamer-test5-Desktop_Qt_5_5_0_MinGW_32bit-Debug;
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\bin;
C:\Qt\Qt5.5.0_Android\Tools\mingw492_32\bin;
C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0;
C:\Program Files\Skype\Phone\ (I dont know why is this included, but it was there when I checked )
I am relatively new to Qt, and never encountered this error before. If you need any code:
.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = GStreamer-test5
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/gstreamer/1.0/x86/include/gstreamer-1.0
C:/gstreamer/1.0/x86/lib/gstreamer-1.0/include
C:/gstreamer/1.0/x86/include/glib-2.0
C:/gstreamer/1.0/x86/lib/glib-2.0/include
LIBS += -L C:/gstreamer/1.0/x86/lib/ -lgstreamer-1.0
and .main:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <stdio.h>
#include "gst/gst.h"
void *__gxx_personality_v0;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
const gchar *nano_str;
guint major, minor, micro, nano;
gst_init (&argc, &argv);
gst_version (&major, &minor, &micro, &nano);
if (nano == 1)
nano_str = "(CVS)";
else if (nano == 2)
nano_str = "(Prerelease)";
else
nano_str = "";
// printf ("This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str);
qDebug() << "This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str ;
return a.exec();
Firstly, I had the error :
undefined reference to `__gxx_personality_v0' , but fixed it by adding *void __gxx_personality_v0; , although I don't know what excatly it is.
Its been three days I struggle with this problem. Any help appreciated, or maybe if you can help me by some code on how to access the header files and libs, or how the configuration of the debugger options / PATH must be.
I am using Qt5.5.0 for Android, for Windows I use MinGW 4.9.2 32 bit compiler and GNU gdb 7.8 as debugger.
Thanks in advance!
I had similar problems in my project that was using both Qt and Gstreamer.
The сause of "undefined reference to `__gxx_personality_v0'" error is that Qt and GStreamer for windows from official sites were built using different compilers and their libstdc++ libraries are not compatible - they are using different exception handling methods.
In fact, GStreamer is pure C library. The only component of it that was written in C++ is taglib library. If you will build this lib from sources using your MinGW compiler, and then replace it in the GStreamer folder, the problem of incompatibility will be solved.
In more detail you can read here: https://github.com/knowthelist/knowthelist.
I managed to solve the above problem. I had to include in the .exe folder (the build-debug folder) all the dlls included, so I tried to run the .exe from there, not run it from Qt, and some errors with dlls missing gave me the names of the dlls. I found some in my library bin folder and some downloaded, and now everything seems fine :)

how to set Windows file permissions in Qt/C++

In my Qt 4.7.4 x64 C++ app I'm building in Qt Creator 2.5.0, I want to give full access to everyone for a file. I'm using QFile::setPermissions, which I believe works fine for Mac and Linux, but it doesn't work for Windows. According to Qt setPermissions not setting permisions, I should use
SetNamedSecurityInfoA("C:\file.txt", SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);
But I don't know what to #include to make it work. I tried:
#ifdef Q_WS_WIN
#include "Windows.h"
#endif
based on what I found here. But when I compile, I get C3861: 'SetNamedSecurityInfo': identifier not found (among some other new errors).
When I mouse over my #include "Windows.h", I get the tooltip: C:\Program Files\Microsoft SDKs\Windows\v7.0\include\Windows.h, and I can press F2 and jump to that file. We have other files in our project that include that same Windows.h, and they compile fine.
How do I set file permissions on Windows for everyone to read/write? If SetNamedSecurityInfo is what I want (I guess SetNamedSecurityInfoW in my case since my users may be running OS's in any language), what do I #include to be able to use it? Better yet, how do I figure out what to #include, so I know for next time I need to use the Windows API?
SetNamedSecurityInfo
Header
Aclapi.h
Library
Advapi32.lib
DLL
Advapi32.dll
A quick search on Google would probably have had this page among it top hits. There you can see which header file and library you need.

Linking Qt in CodeLite

I'm not sure why this is, but 99% of the problems I have with programming in C++ have to do with the gcc linker.
I want to link the Qt library to a project in CodeLite. This is the code I have so far:
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
When I compile, I get the error
/Users/andrew/Dev/C++/COSC 102/elitecod/main.cpp:1:24: error: QApplication: No such file or directory
I have Qt installed (with Homebrew, Mac OS X Lion) in /usr/local/include. Why is this happening, and how can I fix this problem?
The error indicates it can't find the file QApplication. You need to add the Qt 'include' directory to the list of places the compiler should look for it and other header files.
A brief google seems to indicate you may have other problems with Qt, you might want to keep this link handy.

getting the right compiler for C++

I am trying to learn c++ but most of the tutorials and books I have read or looked up teaches you this...
(I am assuming like most tutorials, they are teaching in the beginning to code either in win32 console or CLR console. In either case the following does not work.)
#include <iostream>
int main( )
{
std::cout << "Hello World\n";
return (0);
}
The IDE that i have is Visual C++ 2008 Express edition and they accept code like this
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Or like this
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
Honestly I do not no the difference in none of these and I am not sure if I should just download a older compiler so that it works. If someone can tell me what the difference in these are and where to go from there. That will help tremendously. Thanks
[Edited]
I am trying to do a simple hello world. But I get the error "system can not find path specified." I have screenshot that shows what the error looks like. It also is saying that my project is out of date when I clearly save the file before I build it. Apparently it can not find the executable file. I went to the debug fold and did not see any .exe file.
[Edited]
Ok, now When I try to build the project I get the following errors
1>------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>test.cpp
1>c:\users\numerical25\desktop\test\test\test.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2653: 'std' : is not a class or namespace name
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Users\numerical25\Desktop\test\test\Debug\BuildLog.htm"
1>test - 2 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Here is the code I used
#include <iostream>
#include "stdafx.h"
int main( )
{
std::cout << "Hello World\n";
return (0);
}
Note: I tried using it with and without the #include "stdafx.h" When I tried it without the #include "stdafx.h", it said I might be missing it.
Not sure what you're asking. The first two examples you gave are valid C++ programs that should (will) compile with VC++. The third example is a C++/CLI program that must be compiled with the /CLR compiler switch (this is called Managed C++).
EDIT: Adding more specific information (from a comment below):
The first two examples are standard (native) C++ (albeit, the second example has MS-proprietary macros). They compile to native code. The third is C++/CLI (a "managed" extension to C++). It compiles to managed (.NET) code. Only the third snippet interacts with the .NET framework in any way. All three are absolutely buildable and runnable using the appropriate projects in VS 2008 (no command line necessary)!
Based on your latest update, it looks like you have probably modified some project properties and changed some paths. The app is building, but when you try to run it via VS (you should do this with <Ctrl>+F5, by the way), the executable cannot be found (there are several ways you could have messed this up by changing or playing with various settings).
Please note the difference between building and running. Building is the process of compiling and linking your source code. Running is launching the resulting executable. You seem to be confused between these (judging from your complaints about the "...out of date" dialog box). It is normal to get the "...out of date" dialog box if you try to run without rebuilding after you have made a change to the project (even if that change is saved). Just make sure you click "yes." You need to build the project before you can run it.
My recommendation is to completely delete your project and solution. Create a new empty project, as suggested elsewhere in this now-very-heavyweight thread, and don't modify any project settings. If this doesn't work, something is seriously wrong!
ANOTHER EDIT: Just for completion, since this question kept changing:
As others have already pointed out, your ultimate problem with the first snippet is the use of precompiled headers (PCH). PCH are turned on by default in new VS C++ projects. Their purpose is to speed compilation when many implementation files include the same set of headers -- preventing the compiler from having to parse the header files for each compilation unit.
You have three options:
(Recommended) Disable PCH -- Project Properties --> Configuration Properties --> C/C++ --> Precompiled Headers: Set Create/Use Precompiled Header to Not Using Precompiled Headers. (You don't need to do anything with the "stdafx.h" file or the #include for it.)
Place your commonly used #includes in "stdafx.h". In your case, you would put #include <iostream> in "stdafx.h".
Place your #includes after `#include "stdafx.h". Microsoft requires that the "stdafx.h" be the first included file in a compilation unit.
A minor point, which I don't see elsewhere in the answers: When using precompiled headers, such as your stdafx.h, you need to include them first. Change it to:
#include "stdafx.h"
#include <iostream>
and that should fix the errors about it.
Alternatively, it may be easier to simply switch off precompiled headers: Project > Properties > Configuration Properties > C/C++ > Precompiled Headers > Switch first option to "Not using precompiled headers". They can be useful for big projects but will just be awkward and annoying while you're learning, since they have extra rules (like this "must be included first") which aren't requirements of standard C++ .
The "difference" is pedantic. The latter are just Microsoft-specific entry points.
As you are learning C++, I recommend you use a compiler, and preferably an operating system that lets you focus on C++, and not the platform. For this I recommend g++, on an Linux distribution such as Ubuntu.
Try this tutorial, there are many others that are similar that quickly let you overcome being tied to the tools, and focus on C++.
int main();
int main(int argc, char* argv[]);
These are standard C++.
int _tmain(int argc, _TCHAR* argv[]);
int wmain(int argc, wchar_t* argv[]);
These are Windows-specific to handle Unicode arguments. See What is the difference between _tmain() and main() in C++?.
int main(array<System::String^>^ args);
This is not C++. This is C++/CLI.
For best portability, always use the first form.
Also,
int main(int argc, char** argv, char** envp);
This is a usually seen POSIX extension. Windows supports this form of main too. The envp means (pointer to) environment variables.
int main(int argc, char** argv, char** envp, char** apple);
This is for Mac only, obviously.
void main();
And this is wrong (nonstandard, some compilers (e.g. gcc) will reject it).
Visual C++ Express will compile the first example just fine.
However, you need to ensure the proper project settings:
Create an "Empty Project"
"Add a new item..." to the project via the "Project" menu. Select C++ (.cpp) file.
Copy/Paste code into new file
Press F5 to compile and run.
When "Project is out of date" dialog appears, press "Yes" (build the project)
The steps above ensure VC++ Express does not treat your file as a special Win32/Windows console application.
EDIT: added additional step 5 to prevent "Can't find..." dialog.
I managed to get the same dialog by making sure the exe file does not exist, and answering "No" to the build dialog. With a clean, empty project the exe file does not exist yet. It must be built first. If you answer "no" don't build it, VC++ dutifully does not build the exe and later complains about not being able to find it when it tries to run it later.
As STingRaySC pointed out, all three of your examples will compile in VC2008 express; it's just that examples 2 and 3 are what VC2008 Express will load up initially when you create a project (one of the examples is for Managed C++, as STingRaySC mentioned).
You can just delete the code in your second example (the C++ Win32 Console Application project) and paste in the more standard hello world program from your first example. It should compile and run just fine in VC2008 Express - it did for me.
I. Precompiled header
#include "stdafx.h"
is some kind of tricky stuff that comes your way.
If you create a project VC will normally switch on precompiled header.
This means that one header stdafx.h is created which is compiled only once.
This is done to speed up compile time in big environments. If you start C++
it will confuse you.
If you use stdafx.h it has to be the first header in the cpp file.
II. Unicode (Utf16)
int _tmain(int argc, _TCHAR* argv[])
Microsoft uses UTF16 to implement unicode strings.
This means you get two versions of main.
int main(int argc, char* argv[])
int main(int argc, wchar_t* argv[])
This is also confusing if you start.
To simply start you can use whatever editor you want.
Create the file.
Open a Visdual studio 2008 command prompt
cl main.cpp
main.exe
and you will see Hello World using code from books.
Afterwards try to understand some of the settings of VC.
But you should always use an empty project.
Else you have to care about stdafx, UNICODE, ...
_tmain with the _TCHAR argv is the way the C runtime allows you to handle unicode. If _UNICODE is defined, then _tmain will expand to wmain, and the _TCHAR argument will be of type wchar_t. If _UNICODE is not defined, then _tmain will expand to main, which will be the ANSI standard.
Therefore, so long as _UNICODE is not defined, the second snippet you posted is compliant with the standard.
Lots of waxing lyrical and some misinformation for you sift through already, but I suggest following wonsungi's advice. But to clarify his advice:
File->New->Project
Select Project Type "Win32", then Template "Win32 Console Project"
Give the project a name and location
OK
Select "Application Settings"
Check "Empty Project"
In the "Solution Explorer", right click the "Sources" folder, then Add->New Item
Type the name of the file, in the "name" box using a .cpp extension (you can ignore the templates if you wish).
Enter your code in the new file.
Woot!! I figured it out!!! Below is my original code
#include <iostream>
int main( )
{
std::cout << "Hello World\n";
return (0);
}
It was missing the header file #include "stdafx.h" . So I had to include it in there so I added it like this
#include <iostream>
#include "stdafx.h"
int main( )
{
std::cout << "Hello World\n";
return (0);
}
I was still getting an error like what you see in my edited question at the bottom. So What I did is I took #include and added it in my header file and then it worked!!!!!
Even the the books and alot of tutorials show to add #include to the actual cpp, for some reason in express edition I had to add it to header for it to work. I don't know WHY but it's a solution and now it works.
Download and install Dev-C++ on your system. If the code doesn't work on Visual C++, try it out on Dev-C++ (which uses the GCC compiler). You may get the same results or a different error message. Whenever you get an error message you don't understand, do a Internet search for the error message.