0

I started studying how to integrate GLFW, GLAD and OpenGL in my Qt5 project. I am getting this stdlib.hno such file or directory error. The example I am trying to run is from official OpenGL documentation. This document describes very well the procedure for running the project and from here all the other sessions.

My stdlib.h is present on /usr/include/stdlib.h as it is possible to see from this print screen:

path In addition to that I have this strange error where the compiler expects curly brackets but could not figure out the reason of this error:

bracket error A more detailed description of the error is here:

detailed_error I have been researching a lot this error, I looked here, and here and even I used this source but could not figure out what the problem is and how to link the library, which is already in the shown path.

The snipped of code is:

helloOpenGL.pro

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
        main.cpp

LIBS += -L "/usr/lib" \
      -lX11 -lpthread -lXrandr -lXi -ldl -lGL

INCLUDEPATH += "/usr/include"
LIBS += -L "/usr/include/GLFW" \
      -lglfw3

and the main includes I have on the main.cpp are the following:

#include <../glad/glad.h>
#include <../GLFW/glfw3.h>
#include <iostream>
#include <stdlib.h>

Thanks for shedding light on this issue.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Emanuele
  • 2,194
  • 6
  • 32
  • 71

1 Answers1

1

Try changing

#include <../glad/glad.h>
#include <../GLFW/glfw3.h>
#include <iostream>
#include <stdlib.h>

to

#include <cstdlib>
#include <iostream>
#include "../glad/glad.h"
#include "../GLFW/glfw3.h"

and see if that changes the error. Changing to cstdlib over stdlib.h is because stdlib.h is a C header not a C++ header, and cstdlib does some namespace stuff and a few slight modifications to make it a bit more C++ish as described here. As for changing <> to "" with the glad and GLFW headers, that just changes where the preprocessor searches for the headers which might be related to your error too.

As for the issue, headers and their order in C++ are important. I have a gut feeling that the ordering here is causing some issue. Please change it around and if it is not fixed, hopefully it reveals a little bit more about the issue.

  • Hi CustardPaint, thanks for the comment. Changing according to your advice worked partially. It now triggered the following two undefined reference `gladLoadGLLoader` and to `glad_glViewPort`. See the compiler output. ![compiler output](https://i.imgur.com/vkS90Vg.png). According to [this post](https://stackoverflow.com/questions/41776746/how-to-set-up-in-netbeans-8-1-to-successfully-compile-an-opengl-code-which-uses) there seems to be a specific order for including the libraries. ![Here](https://i.imgur.com/o8xaX4L.png) is how I modified the file `helloOpenGL.pro` – Emanuele Feb 25 '19 at 16:05
  • Also [from the official example](https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/1.1.hello_window/hello_window.cpp) my compiler identifies the two undefined references [here](https://i.imgur.com/09RfhPB.png) and [here](https://i.imgur.com/obSxNE5.png). Any idea of what could be going on? Thanks so far. – Emanuele Feb 25 '19 at 16:13
  • Ok Problem Solved. The solution is a little bit long I hope will benefit others that encountered this problem: **1)** As CustardPaint suggested, it is very important the order of the includes, [see here](https://i.imgur.com/FRxVFDJ.png); **2)** from [official documentation](https://learnopengl.com/Getting-started/Creating-a-window) download [GLAD](https://glad.dav1d.de/) follow the instruction. **3)** Remember to `#include "glad.c"`, **4)** the [following libraries](https://i.imgur.com/o8xaX4L.png) should be added so that the compiler can link them to your project, **5)** Compile & done! – Emanuele Feb 25 '19 at 17:13
  • Thanks CustardPaint, I am marking your answer as correct because even though it didn't completely solved the problem, it triggered for other solvable errors. – Emanuele Feb 25 '19 at 17:15