I just installed OpenCV-3.4.1 on Ubuntu 18.04. I am able to compile my C++ files only when I run the g++ command with pkg-config --cflags --libs opencv
Is it possible for me to compile the c++ file without using these additional flags
How can I tell g++ to automatically look at /usr/include/opencv for the .h files everytime
Asked
Active
Viewed 1,095 times
1

Rajarishi Devarajan
- 581
- 4
- 14
1 Answers
2
For adding to the include path see this question: How to add a default include path for GCC in Linux?
A better solution however is to write a shell script to compile your code rather than having to type in the command line every time.
The best solution is to use a proper build system which will save you a lot of pain in the future, just a few of the many available options:
- GNU make
- cmake
- google gyp
- google gn
- ninja

Alan Birtles
- 32,622
- 4
- 31
- 60
-
I tried the simplest option of adding CPLUS_INCLUDE_PATH to my .bashrc file and it didn't solve the problem. I got an error message saying stdlib.h couldn't be found – Rajarishi Devarajan Jun 15 '18 at 09:14
-
What exactly did you add and what is the resulting error message? – Alan Birtles Jun 15 '18 at 09:15
-
My opencv header files are stored in /usr/include. Therefore I added CPLUS_INCLUDE_PATH=/usr/include. I got a new error message saying stdlib.h not found. All the other reference errors to opencv functions have disappeared though – Rajarishi Devarajan Jun 15 '18 at 09:19
-
Consider suggested CMake tool. – Michał Walenciak Jun 15 '18 at 11:49