Including dlib in Qt project - c++

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.

Related

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

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.

compilation error of OpenCV cpp code using Qt

I am using a very basic OpenCV code to compile using Qt but every time the following errors are coming.
OpenCV version
OpenCV version : 3.4.3
Major version : 3
Minor version : 4
Subminor version : 3
My code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat I = imread("path/filename.ppm", 1);
imshow("conv_image",I);
waitKey();
return 0;
}
.pro file
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you
use
# any feature of Qt which as been marked deprecated (the exact
warnings
# depend on your compiler). Please consult the documentation of
the
# deprecated API in order to know how to port your code away from
it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use
deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a
certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables
all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Given Error
:-1: warning: libopencv_core.so.3.4, needed by /usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
/usr/local/lib/libopencv_core.so.3.4:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status
In my .pro file, I have used the following line(from the different link I have found 3 ways, I have tried all but failed)
First
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Second
INCLUDEPATH +=/usr/local/include/opencv
LIBS +=`pkg-config --libs opencv`
Third
I have used information from here
Please give me suggestion to solve the issue.

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.

Linking with libconfig in c++ on OSX

I have a config file that contains:
#include "libconfig.h++"
I have installed libconfig via homebrew and I am trying to compile my c++ program so that I can use the library but I am having trouble linking to it.
The location of the libconfig .a files is located at /usr/local/Cellar/libconfig/1.4.9/lib/
The documentation says: To link with the library, specify ‘-lconfig++’ as an argument to the linker.
So I have been trying variations on g++ config.cpp -L /usr/local/Cellar/libconfig/1.4.9/lib -lconfig++ -o out.o
But I getting the same error message:
config.cpp:4:10: fatal error: 'libconfig.h++' file not found
#include "libconfig.h++"
Can someone please explain what I am doing wrong?
There is nothing about linker. The compiler says that it can't find the file you include in your cpp. If you have installed libconfig correctly, changing #include "libconfig.h++" to #include <libconfig.h++> will solve the problem. If it does not help, it would mean that there is no "libconfig.h++" in your include path.