<glad/glad.h>: No such file or directory - c++

I'm following this tutorial to learn OpenGL, but I'm having trouble compiling since the compiler can't find one of the header files.
This is the file I'm trying to compile:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
return 0;
}
To compile, I'm using
$ gcc -o sandbox sandbox.cpp -lGL -lGLU -lglut
and I get the following error:
sandbox.cpp:1:23: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
^
compilation terminated.
I followed the first two sections of this wiki
to install OpenGL and libraries.
I think the problem is either the wrong compile command or a flaw in my OpenGL installation.

GLAD is a function loader for OpenGL. This tutorial explains how to set it up.
The tutorial explains the purpose of GLAD:
Since there are many different versions of OpenGL drivers, the location of most of its functions is not known at compile-time and needs to be queried at run-time.
Setup of GLAD involves using a web server to generate source and header files specific to your GL version, extensions, and language. The source and header files are then placed in your project's src and include directories.

If you are looking at this simple GLFW example you can remove the glad/gl.h include, and the
gladLoadGL(glfwGetProcAddress);
line further down.
If you are on linux, ubuntu for example,
you don't need glad, just add these 2 headers instead:
#include <GLES2/gl2.h>
#include <EGL/egl.h>
If the example is saved as glfw_ex2.c you can compile it at the command line like this:
g++ glfw_ex2.c -lglfw -lGLESv2
Of course, linmath.h must be present in the same directory for this example.
If anything is missing, you can install it like this and try compiling again:
sudo apt install libglfw3-dev libgles2-mesa-dev libegl1-mesa-dev
sudo apt install build-essential
then run it like this:
./a.out

Related

Issues including Eigen for simple C++ TensorFlow Lite test program

I compiled the library for the C++ API for TensorFlow Lite (r1.97) using the script ${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/build_rpi_lib.sh following the steps suggested at this official page (Native Compiling, downloading the necessary libraries), where ${TENSORFLOW_ROOT} is the root folder where I cloned the repository.
I am trying to compile this simple test.cpp program:
#include <memory>
#include "tensorflow/lite/interpreter.h"
int main(void)
{
std::unique_ptr<tflite::Interpreter> interpreter(new tflite::Interpreter);
}
using the command:
gcc-6 test.cpp -I${TENSORFLOW_ROOT} -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/eigen -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/protobuf/src -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads -L${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/gen/rpi_armv7l/lib -lstdc++ -ldl -ltensorflow-lite
The list of includes was suggested in the Integrating TensorFlow libraries page (specifically from the section iOS). Compilation fails with the following error related to the inclusion of Eigen:
${TENSORFLOW_ROOT}/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory
#include "unsupported/Eigen/CXX11/Tensor"
I found several links where an apparently similar problem is discussed (such as this one), but the proposed solutions involve using references to the TensorFlow python package which is something that is not possible in my case (and it feels quite patchy - I am not considering using python for this project).
I also tried using a different include path to Eigen (e.g. ${TENSORFLOW_ROOT}/third_party/eigen3):
gcc-6 test.cpp -I${TENSORFLOW_ROOT} -I${TENSORFLOW_ROOT}/third_party/eigen3 -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/protobuf/src -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads -L${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/gen/rpi_armv7l/lib -lstdc++ -ldl -ltensorflow-lite
and also this causes Eigen related compilation errors of this sort:
...
${TENSORFLOW_ROOT}/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply
#include "unsupported/Eigen/CXX11/Tensor"
...
${TENSORFLOW_ROOT}/third_party/eigen3/Eigen/Core:1:22: error: #include nested too deeply
#include "Eigen/Core"
...
Any suggestions on how to solve this issue? What is the right set of include paths?
Turns out I was including the wrong folder. Instead of ${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/eigen or ${TENSORFLOW_ROOT}/third_party/eigen3, the right one is ${TFLITE_ROOT}/tensorflow/lite/tools/make/downloads/eigen.
I am still puzzled by the number of eigen folders inside the repository:
find . -name "eigen*" -type d
./third_party/eigen3
./tensorflow/lite/tools/make/downloads/eigen

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.

Compiling SDL2 Error in Terminal (Confused about how to include SDL2 library)

I'm learning SDL2 right now and I'm working in XCode for the most part as I code. However, I want to run my program in terminal to use valgrind, but whenever I try, I get this error:
fatal error: 'SDL2/SDL.h' file not found
I'm compiling in a really simple way as follows:
g++ Camera.cpp LTexture.cpp LTimer.cpp LWindow.cpp Player.cpp Tile.cpp TileMap.cpp main.cpp -o main
I know that I'm supposed to be including the SDL2 library somehow, but I'm unsure of how to do that. Right now, the framework is sitting in the folder /Library/Frameworks/SDL2.framework
Any help on this would be greatly appreciated. Thanks in advance.
Add
-I/Library/Frameworks/SDL2.frameworks/Headers
to your g++ command and change
'SDL2/SDL.h'
include to just
'SDL.h'
in your header/(s) since /Library/Frameworks/SDL2.frameworks/Headers doesn't contain an SDL2 folder (usually)
Now that you changed the #include "SDL2/SDL.h" to #include "SDL.h" you want to go open your Xcode project, select your target, go to build settings and add /Library/Frameworks/SDL2.frameworks/Headers to Header Search Paths in order to fix Xcode's 'Couldn't find 'SDL.h'' error message.
Update:
Another way would be linking (using ln) /Library/Frameworks/SDL2.frameworks/Headers to /usr/local/include/SDL2, add -I/usr/local/include/SDL2 to your g++ command
and leave the #include as is ('SDL2/SDL.h')

Working with CLang in c++

I have a compilation error in my program related to the included files, in my program I am including this files:
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
The error message I get when I compile the program using g++ is:
In file included from /usr/include/clang/AST/APValue.h:17:0,
from /usr/include/clang/AST/Decl.h:17,
from /usr/include/clang/AST/RecursiveASTVisitor.h:17,
from FindClassDecls.cpp:2:
/usr/include/clang/Basic/LLVM.h:20:34: fatal error: llvm/Support/Casting.h: No such file or directory
compilation terminated.
I don't have any idea how to solve the problem, and also I am not sure that I installed the CLang library correctly, so can you please tell me how to solve the problem or how to install it correctly on linux (Ubuntu).
It seems that you have the Clang headers installed, but not the LLVM headers (which Clang relies upon). When you are compiling your code, you need to pass the path of LLVM headers with -I to your compiler, as usual.
I'd grab a pre-built Clang+LLVM from the Download page and compile/link against that.
sudo apt-get install libclang-3.8-dev # or libclang-3.9-dev

how do i get rid of these compiler errors in glu.h?

trying to use this tutorial on 64-bit windows 8 with netbeans and cygwin 4.8.1.
i get many errors like this: /usr/include/w32api/GL/glu.h:68:79: error: expected ‘)’ before ‘*’ token.
on statements like this: void APIENTRY gluQuadricCallback(GLUquadric *qobj,GLenum which,void (CALLBACK *fn)());
the pointer on error message points to the * before the fn().
edit: including windef.h gets rid of the compiler error messages.
i am left with a bunch of undefined references like: glfwInit
edit2: using André Fischer's ideas, i can get a clean compile (you need to add the directory and a -l option for the linker).
i now have a: skipping incompatible ../../../../../Windows/SysWOW64/opengl32.dll when searching for -lopengl32 and: undefined reference to `_imp_vsnprintf'. so it looks like i have a 32/64 bit problems and an undefined external.
there must be a saner way to get opengl working on windows.
I assume you mean Tutorial 1: Opening a Window and are using Netbeans' builtin build system instead of CMake.
The order in which you include the header files is important (source). Try it like this:
#include <windef.h> // According to comments above
#include <GL/glew.h> // Before any gl headers
#include <GL/gl.h>
//#include <GL/glext.h> // Linux headers
//#include <GL/wglext.h> // Windows headers - Not sure which ones cygwin needs. Just try it
#include <GL/glu.h> // Always after gl.h
#include <GL/glfw.h> // When all gl-headers have been included
Create a directory named "include" in your project directory with a subfolder "GL".
Grab the binaries (32 bit, MinGW) from the GLFW Download Site and put the .dll/.so into your build-folder (Or extract them somewhere and add them to the search directories) and the header files into "include/GL".
Also the glfw code in the tutorial is slightly outdated; It does not work with glfw3 anymore.
You'll have to update it using GLFW's conversion guide/try this version (which I haven't been able to test, since I'm currently not at home) or use glfw2.
Finally download the GLEW sources and build it by following the instructions in the README.txt. Put the .dll/.so into your build-folder (or add to search directories) and the header files into "include/GL".
Add following to your Compiler-Flags:
-Iinclude/
Finally add following arguments to your Linker:
-L/lib -lglu32 -lopengl32 -lGL -lGLU -lglfw -lglew
You should be able to compile the tutorial now.
Edit: Added instructions for building GLEW, GLFW and completed my answer to include building everything from scratch.
Edit2: Linked glfw3-version of the tutorial-code.
Edit3: Added missing linker options.