This looks to be an easy one but I am not able to get it through.
So, I have installed OpenCV library and the executables are present at
/usr/local/opt/opencv/lib
apple#Apples-MacBook-Air.local:~/AGV/Vision$ ls /usr/local/opt/opencv/lib
cmake libopencv_fuzzy.dylib
libopencv_saliency.dylib
libade.a libopencv_gapi.4.5.3.dylib
libopencv_sfm.4.5.3.dylib
libcorrespondence.a libopencv_gapi.4.5.dylib
libopencv_sfm.4.5.dylib
....
....
And my $PATH variable looks like this:
apple#Apples-MacBook-Air.local:~/AGV/Vision$ echo $PATH
/usr/local/opt/opencv/lib:/usr/local/bin:/usr/local/opt/libxml2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
If you notice, the path to installed libraries is part of the $PATH variable. Problem is that when I compile a simple program of OpenCV library, it says it can not find the file which seems frustrating.
Sample code:
#include <iostream>
#include <opencv2/highgui.hpp>
int main() {
}
Error I get is:
apple#Apples-MacBook-Air.local:~/AGV/Vision$ g++ agv.cpp
agv.cpp:2:10: fatal error: 'opencv2/highgui.hpp' file not found
#include <opencv2/highgui.hpp>
If I have added the library path to $PATH variable, shouldn't g++ take the libraries from that path and proceed?
What am I missing here?
Related
I want to use gcc in docker/singularity image to compile a program. Using local gcc, I use gcc tc.c -I PATH_TO_LIB without any error. To use the gcc in the image, I use the following command line.
singularity exec gcc_5.1.0.sif gcc tc.c -I PATH_TO_LIB
But the problem is that gcc cannot find the .h file in the library path. It returns the following error.
fatal error: csmith.h: No such file or directory
#include "csmith.h"
When compiling demo OpenCV code, such as,
g++ HoughLines_Demo.cpp `pkg-config opencv --cflags --libs` -o HoughLines_Demo,
the compiler cannot find the header files:
HoughLines_Demo.cpp:7:33: fatal error: opencv2/imgcodecs.hpp: No such file or directory
#include "opencv2/imgcodecs.hpp"
^
If I downloaded opencv-3.0.0 correctly, these header files do exist on my computer already, right? If so, what do I need to do to link them correctly?
The exact error message:
Running:
Ubuntu 14.04,
g++-4.8,
4.8.4-2 ubuntu1~14.04
Update:
Looking up this problem more, the problem should be outdated OpenCV code. I ran pkg-config --modversion opencv which returned 2.4.8. I could have sworn I was running 3.0.0 . What is going on here?
So I have a child.c file and I want to compile and run it in my main.c file using the system() function of stdlib.h.
child.c:
#include<stdio.h>
int main(){
printf("I am the child\n");
return 0;
}
main.c:
#include <stdio.h>
#include <stdlib.h>
int main() {
system("cd ~/Desktop/HW3/HW3");
system("gcc -o child child.c");
system("./child");
return 0;
}
everything worked fine when I compile and run main.c in terminal using the following command
abcs-mbp:HW3 abc$ cd
abcs-mbp:~ abc$ cd ~/Desktop/HW3/HW3
abcs-mbp:HW3 abc$ gcc -o main main.c
abcs-mbp:HW3 abc$ ./main
and it ran child.c and printed the following:
I am the child
but when I tried to run the exact same main.c in XCode, XCode gave me the following error:
clang: error: no such file or directory: 'child.c'
clang: error: no input files
sh: ./child: No such file or directory
anybody know why this is happening? I think it has something to do with path, but how can I tell XCode the path of child.c and then tell it to compile child.c?
I also tried
system("cd ~/Desktop/HW3/HW3");
system("gcc -o child child.c");
system("./child");
and
system("/Users/vqianxiao/Desktop/HW3/HW3/ gcc -o child child.c");
but nothing seems to work... any help is appreciated!
the reason that it does not work is a combination of things
1) each 'system' call is run in a separate shell instance,
so the second 'system' call
starts from the directory where the main program is running.
2) things do down from there
a suggested fix:
system("cd ~/Desktop/HW3/HW3; && gcc -o child child.c; && ./child;");
notice, all one system call, terminators at end of commands, and linked by && so one command must be successful to continue on to the next command
I have read the related questions but I cannot solve my problem.
I'm trying to compile a OpenCV C++ code on raspberry pi.
OpenCV requires cv.h to be included. When I try to compile I get:
"fatal error: cv.h: No such file or directory."
I have tried these:
g++ -c -Ihome/pi/OpenCV-2.3.1/include/opencv file.cpp
g++ -c -Ipi/OpenCV-2.3.1/include/opencv file.cpp
g++ -c -IOpenCV-2.3.1/include/opencv file.cpp
Do any of you have any ideas?
This is a general question and not related only to OpenCV.
For the general problem of including any header file
1. Try to see if the file is really at the included directory or no
2. Try to look for it in the folder
I have a problem with the linking simpliest test program in QTCreator:
CODE:
#include <QtCore/QCoreApplication>
#include <cv.h>
#include <highgui.h>
#include <cxcore.hpp>
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat M(7,7,CV_32FC2,Scalar(1,3));
return 0;
}
.pro file:
QT -= gui
TARGET = testopencv
CONFIG += console
CONFIG -= app_bundle
INCLUDEPATH += C:/OpenCV2_1/include/opencv
TEMPLATE = app
LIBS += C:/OpenCV2_1/lib/cxcore210d.lib \
C:/OpenCV2_1/lib/cv210d.lib \
C:/OpenCV2_1/lib/highgui210d.lib\
C:/OpenCV2_1/lib/cvaux210d.lib
SOURCES += main.cpp
I've tried to use -L and -l like LIBS += -LC:/OpenCV2_1/lib -lcxcored
And in .pro file:
QMAKE_LIBDIR += C:/OpenCV2_1/lib/Debug
LIBS += -lcxcore210d \
-lcv210d \
-lhighgui210d
The errors are like:
debug/main.o:C:\griskin\test\app\testopencv/../../../../OpenCV2_1/include/opencv/cxcore.hpp:97: undefined reference to cv::format(char const*, ...)'
Could anyone help me? Thanks!
In Visual Studio it works but I need it works in QTCreator..
Qt uses the MinGW compiler and linker. It will happily link OpenCV .libs when you use the C interface. However due to ABI issues, it will not link C++ modules.
You will have to either restrict yourself to the C interfaces only (i.e. no cv::Mat), or get OpenCV to compile with MinGw (or compile Qt in/with VS). Also, see this thread.
This is what my .pro file looks like
INCLUDEPATH += C:\\opencv\\release\\install\\include\
LIBS += -LC:\\opencv\\release\\install\\bin \
-lopencv_core240 \
-lopencv_highgui240 \
-lopencv_imgproc240 \
-lopencv_features2d240 \
-lopencv_calib3d240 \
and replace
#include <cv.h>
with
#include <opencv/cv.h>
Above .pro file works perfect for me. I have used mingw to compile OpenCV and using mingw compiler tool chain in Qt.
It seems that QtCreator cannot locate lib files.
Try specifying the include file and libs as follows.
INCLUDEPATH += C:/OpenCV2_1/build/include/
LIBS += C:/OpenCV2_1/build/gpu/x86/lib/cxcore210d.lib
you should refer to build folder if you're using pre-build version of opencv.
(I recommend pre-build version if you're not that familiar with opencv)