Qt5 & OpenGL: stdlib.h: No such file or directory - c++

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:
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:
A more detailed description of the error is here:
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.

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.

Related

Including dlib in Qt project

I am trying to add dlib library to my Qt5 project.
I've build dlib with gcc 4.9.3 using CMake without NO_GUI_SUPPORT (i.e. with GUI) and without ISO_CPP_ONLY. I've compiled it into shared library with CMAKE_INSTALL_PREFIX = my_qt_project_dir/dlib, installed and included it into my project:
# DLIB
INCLUDEPATH += $$PWD/dlib/include/
LIBS += -L$$PWD/dlib/lib/
LIBS += -ldlib
I am including this headers in code:
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
#include <dlib/opencv.h>
but during compilation get this errors
some of them:
/dlib/include/dlib/image_processing/../matrix/matrix_la.h:64:45: error: macro "sign" passed 2 arguments, but takes just 1
/dlib/include/dlib/image_processing/../matrix/matrix_math_functions.h:83:27: error: expected unqualified-id before 'const'
/dlib/include/dlib/image_processing/../matrix/matrix_la.h:1034:9: error: 'matrix' has not been declared
I am using CMake 3.3.1, QtCreator 3.4.2, Qt 5.4.2, gcc 4.9.3 running on gentoo 4.0.9.
How to deal with this?
Someone #defined the word "sign" and it's stomping on the code. Figure out what code creates the sign #define and #include it after other headers.

SDL2_image not found

I am trying to compile the following code which has the headers:
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
However after running the following makefile:
g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image
I get the following error:
fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>
Any suggestions? Not entirely sure about my installation of SDL_image. I am running this on Ubuntu.
This problem can be solved through installing libsdl2-image-dev package:
apt install libsdl2-image-dev
Run apt-file search SDL_image.h
The result will tell you the location of the include file.
For instance, /usr/include/SDL2/SDL_image.h was returned.
So, when you want to include SDL_image.h, write everything after the include/ in between < >.
Thus, includes should look like the following:
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
See the question's comments for the original discussion regarding this solution.
From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.
cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image
or
gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image
Here is the reference -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html
Section 2.2 Compiling.
So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.
For Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks you've got the add both Runtime Binaries and Development Libraries to the compiler and linker. Or else, you'll get the error SDL2_image not found, even with having the dll in your program's directory, this occurs. Hopefully others find this helpful; I had to figure it out myself. Example: If your resources are separate, you'll be adding the two plus your standard SDL2 paths to your compiler and linker. Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework. If you get errors about the image header, include the sub-folder SDL2 from SDL framework in the path and then you should be including SDL2 in the program as: include <SDL.h> rather than include <SDL2/SDL.h>.

Installed freetype through homebrew, can't seem to include headers correctly

On my xcode project, I added the dylib of freetype to the project Link Binary phase.
I ensure /usr/local/include and /usr/local/lib are in search paths in the build settings.
I then include:
#include <freetype2/ft2build.h>
#include FT_FREETYPE_H
But i get an error that freetype.h was not found. Any ideas? I tried including <freetype2/freetype.h> directly, but that leads to more compile problems with include paths in other freetype files.
Looking at the demo programs in "freetype2-demos", I see:
#include <ft2build.h>
#include FT_FREETYPE_H
Also, I think you need your compiler command-line to include -I (path to freetype includes).
For example...
g++ -I (...)/freetype2 myfile.cpp
Here are the instructions. The suggestion there is to compile with something like...
g++ $(freetype-config --cflags) myfile.cpp
...which, if you system is configured correctly, will incorporate the -I option that I previously mentioned.

Connecting Mongodb to C++ API #include problems

I got the mongoshell and Json file all set up. I need help connecting Mongodb to C++
I typed this in the command prompt but it gave a a syntax error. (my file name is ConnectorMain.cpp)
-I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp -o ConnectorMain
This person had the same problem: Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
The reason that there you need to type this in the cmd pmt is because it will allow you to access the weird #inclue files like: #include "mongo/client/dbclient.h"
I've visited http://api.mongodb.org/cplusplus/current/files.html
and this is the dbclient.h file
#pragma once
#ifdef MONGO_EXPOSE_MACROS
#error dbclient.h is for C++ driver consumer use only
#endif
#define LIBMONGOCLIENT_CONSUMER
#include "mongo/client/redef_macros.h"
#include "mongo/pch.h"
#include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/dbclientinterface.h"
#include "mongo/client/gridfs.h"
#include "mongo/client/init.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/syncclusterconnection.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/client/undef_macros.h"
and it is crazy cause of all the headers so I am trying to figure out how to hook this all up and as the forum says it has to do with setting up a -I or -L because it relates to this forum http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/#installing-the-driver-library-and-headers but that is in Linux.
Please help if you know how to do this. p.s. do I need to download boost and perl or something I saw that on another post. Anyways all the help is appreciated!

How to include correct: <SDL2/SDL.h> or <SDL.h> and set -I/usr/include/SDL2?

How to include correct with using gcc: <SDL2/SDL.h> or <SDL.h> and set -I/usr/include/SDL2?
Well, either are valid, but I think its far more polite to use that one that makes the compile command easier and more obvious, ie #include , thus you dont need to alter the include search path.
I think this command will work:
g++ main.cpp -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks -framework SDL2