Compiling c++ with SDL2 in terminal - c++

I have been unable to compile a basic class file to generate a window using SDL2, using both brew and compiling from the SDL site using using...
#include <SDL2/SDL.h>
at the top of the file.
Have also used...
#include <SDL/SDL.h>
#include "SDL"
among others and nearly always get this error
./src/window.cpp:1:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
Something should have worked and just hasn't.

Related

Error in Compiling OpenGL code under Windows

I am trying to compile an OpenGL program.
This is the portion of the code with all the includes:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>
// Usage of degrees is deprecated. Use radians for glm functions.
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "shaders.h"
The file i am trying to run is called mytest1.cpp and i also have shaders.h in the same directory.
In the same directory i have a folder called 'include' And inside two subfolders called 'GL' and 'glm' with all the files inside that are required from the program.
So i go to the directory of the mytest1.cpp and i type g++ mytest1.cpp and i get the error:
mytest1.cpp:14:21: fatal error: GL/glew.h: No such file or directory
#include <GL/glew.h>
^
compilation terminated.
Why does this happen? I also tried to place the 'GL' folder in the root directory and i got the same error

DirectX header files not found (MinGW)

I am using MinGW compiler with the command line and sublime text 3. While including the header files for DirectX into my C++ code, it gave errors saying they weren't found.
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
This results in the following error:
lesson 5.cpp:4:20: fatal error: d3dx11.h: No such file or directory
#include <d3dx11.h>
If I comment out the line it gave an error for, it just gives the same error for the next line.

C++ Boost and ImageMagick++ API issue

While developing Raspberry Pi library compiled by g++4.9.2 I have met compability issue between boost (1.6.2) and ImageMagick++ API (7.0). When compiling this code:
#include <Magick++.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
I got these boost errors:
__assert_fail was not declared in this scope (path_trails.hpp)
...
__assert_fail was not declared in this scope (path.hpp)
...
__assert_fail was not declared in this scope (shared_ptr.hpp)
When deleting #include <Magick++.h> line everything runs fine. Unfortunately I need boost and ImageMagick as well in this source file. How to solve this issue?
A simple workaround is to include Magick++.h after boost.
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <Magick++.h>
I don't have a proper explanation for this problem but it seems to come from a clash when using different headers including assert.h (I had the same problem using the assimp library and ImageMagick) but I don't get why the order matters.
Reproducing your case, assert.h is included in:
cassert for boost
MagickCore/pixel-accessor.h for Magick++.h
If someone has an explanation for this problem feel free to edit.

How to include SDL2 and SDL_image on both Windows and Linux

I've been developing using C++ and SDL2 on Linux and have been using the following form to include SDL2 in my headers :
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
However, I now have need to develop on Windows too, which has a different include declaration. I've read up on it as best I can and have successfully included SDL using #include "SDL.h" and passing -I/usr/include/SDL2 into my makefile. This works fine for SDL, but seems to break SDL_image.
Using :
#include "SDL.h"
#include "SDL_image.h"
results in a long list of errors starting with
undefined reference to `IMG_Load'
Using
#include "SDL.h"
#include <SDL2/SDL_image.h>
with the -lSDL2_image flag results in
undefined reference to symbol 'SDL_FreeSurface'
Both of these errors I know are to do with SDL_image. The only thing that seems to work is
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
with the -lSDL2 -lSDL2_image when compiling, but I'd rather avoid that if possible so that I don't have to use #ifdef to compile on both Linux and Windows.
Can anyone point me in the right direction as to where I'm going wrong please?

Using glut with code blocks in Windows 7

i'm a total novice with OpenGL, and I have to compile a file (my first file using opengl), the headers of the file are :
#include <GL/glut.h>
#include <GL/gl.h>
#include <iostream>
I downloaded glut, put the glut.h in the right folder, and put the glut32lib in the right folder too (in Code Blocks).
I also linked glut32.lib in the linker settings.
But i can not compile, i have errors like this :
....\Desktop\OpenGL\OpenGL\prog3.o:prog3.cxx|| undefined reference to `__glutInitWithExit'|
Please can you help me ?
EDIT : Solution foud here : GLUT compile errors with Code::Blocks
All that was needed was #include before including GL/glut.h
I don't know why...
This was my problem. I found solution for this problem in 2 step.
Step 1: follow instructions in this link: Using OpenGL & GLUT in Code::Blocks
Step 2: add #include <GL/glu.h> before #include <GL/glut.h>
Attention: you must create new project, not blank source file. Just follow how to do it in that link.