Permantly provide path to the headers and linker flags in OpenCV Linux - c++

I have OpenCV 4.5.1 installed in Linux. But each time I restart I have to separely provide path to the headers and linker flags. and then compile ?
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/parallels/opencv4.5-custom/lib/pkgconfig
pkg-config --cflags --libs opencv4
and then
g++ -Wall -std=c++11 -o main main.cpp $(pkg-config --cflags --libs opencv4)
I just want to run the g++ comand each time

Related

unable to compiling c++ with openCV even using 'pkg-config --cflags --libs opencv` in Linux

good morning,
please I need help-
I have a file: s.cpp
that uses:
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
and I wrote a makefile like this:
s: s.o
g++ s.o -o s
s.o: s.cpp
g++ s.cpp -c `pkg-config --cflags --libs opencv`
clean: rm -f s
and got the error:
g++ s.cpp -c `pkg-config --cflags --libs opencv`
s.cpp:9:10: fatal error: opencv2/highgui.hpp: No such file or directory
#include <opencv2/highgui.hpp>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
please, I dont know what to do
please someone can help?
if you are are trying to link more libraries all together in one time using the pkg-config command, I solved my problems on code::blocks with the command
pkg-config --libs --cflags opencv4
written in the project->build option->"program name"->linker settings->other linker option

compiling c++ projects with dlib library on linux

I want to use dlib library for my c++ projects in linux. I have installed it successfully and able to compile and run the .cpp samples files given under the dlib. I have compiled the sample files through the
"g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp" given in [http://dlib.net/compile.html][1]
but I am unable to use the same command to run .cpp files which are the outside dlib-18.18/examples directory
Can someone help me out with compiling c++ file (with dlib library usage) from any user directory in linux?
I came to know that we have to include the path of dlib installation folder while trying to compile it from any other user directory. So I tried the command
" g++ -O3 -I/home/praneeth/computervision/.. ../dlib/all/source.cpp -lpthread -lX11 project3_face.cpp -o project_face pkg-config --cflags opencv pkg-config --libs opencv"
but it gave me the result:
g++: error: ../dlib/all/source.cpp: No such file or directory
Note: dlib-18.18 folder is present in my /home/praneeth/computervision/
I don't know how correct is this but it got compiled when I ran the command like: g++ -O3 -I/home/praneeth/computervision/dlib-18.18 /home/praneeth/computervision/dlib-18.18/dlib/all/source.cpp -lpthread -lX11 project3_face.cpp -o project_face pkg-config --cflags opencv pkg-config --libs opencv any comments on this regarding why this works?
g++ -Wl,-V -std=c++11 -o3 -I/home/user/dlib-19.6 /home/user/dlib-19.6/dlib/all/source.cpp -lpthread -lX11 -o Test Test.cpp pkg-config opencv --cflags --libs

libxml++/libxml++.h: No such file or directory

I am using ubuntu 12.4 g++ i'm working on libxml++ library I have included this library in my program but I am getting an error saying
libxml++/libxml++.h: No such file or directory
i also tried compiling using g++ main.cc -o main pkg-config --cflags --libs libxml++-2.6 but it is not working. I have installed the latest libraries using sudo apt-get install libxml++.
While compiling for libxml we have to use these options. pkg-config --cflags --libs libxml++-2.6 this should be in single quotation mark / Backticks ("`", grave accents), .
So the command should be like this.
$ g++ main.cc -o program `pkg-config --cflags --libs libxml++-2.6`
or go through this once. http://developer.gnome.org/libxml++/stable/

pkg-config can't find opencv

I installed opencv on a lubuntu 12.10 distro. Then when I try to compile a code which is using opencv it says it can't find it. So I try in a terminal :
pkg-config --cflags --libs opencv
It answers me that it can't find opencv. But the files are installed in /usr/lib. I don't understand why it can't find them.
You have to put pkg-config --cflags --libs opencv at the end of your g++ line. For example :
g++ test.cpp -o test `pkg-config --cflags --libs opencv`
Compiles
g++ `pkg-config --cflags --libs opencv` test.cpp -o test
Doesn't compile and have undefined reference.
For OpenCV 4 you might have to use:
pkg-config --cflags --libs opencv4
(Note the 4 in the end!)
From OpenCV 4:
add -DOPENCV_GENERATE_PKGCONFIG=YES to cmake build arguments.
Use YES, ON is not working anymore.

C/C++: how to figure out link flags?

How do I reliably figure out link flags for libraries? I always end up googling/digging manuals.
Is there a way to list libraries available for linking, with names and/or descriptions?
edit: Linux system, GNU build chain, classics.
On most Linux systems, you can use pkg-config to list out the compiler options for a given library. For example:
g++ example.cpp $(pkg-config --cflags --libs libpng)
becomes
g++ example.cpp -I/usr/include/libpng12 -lpng12
Or an example with slightly more complicated output:
$ pkg-config --cflags --libs gthread
-D_REENTRANT -I/usr/include/glib-1.2 -I/usr/lib64/glib/include -lgthread -lpthread -lglib