No such file or directory error when compiling C++ file with OpenCV headers -


i'm on red hat linux. i'm having (probably newbie) problem includes in c++ file. created following simple opencv script,

#include "opencv2/highgui/highgui.hpp" using namespace cv;  int main(int argc, char ** argv){     mat img = imread( argv[1], -1 );     if ( img.empty() ) return -1;     namedwindow( "example1", cv::window_autosize );     imshow( "example1", img );     waitkey( 0 );     destroywindow( "example1" ); } 

then in terminal entered

g++ my_simple_script.cpp 

and got errors

newfile.cpp:1:39: error: opencv2/highgui/highgui.hpp: no such file or directory newfile.cpp:3: error: 'cv' not namespace-name newfile.cpp:3: error: expected namespace-name before ';' token newfile.cpp: in function 'int main(int, char**)': newfile.cpp:6: error: 'mat' not declared in scope newfile.cpp:6: error: expected ';' before 'img' newfile.cpp:7: error: 'img' not declared in scope newfile.cpp:8: error: 'cv' has not been declared newfile.cpp:8: error: 'namedwindow' not declared in scope newfile.cpp:9: error: 'img' not declared in scope newfile.cpp:9: error: 'imshow' not declared in scope newfile.cpp:10: error: 'waitkey' not declared in scope newfile.cpp:11: error: 'destroywindow' not declared in scope 

i added

/home/m/maxwell9/2.4.3/include 

to path, 2.4.3 indicates version of opencv i'm using. when type

echo $path 

i see

/opt/apps/jdk1.6.0_22.x64/bin:/apps/smlnj/110.74/bin:/usr/local/cuda/bin:/sbin:/bin:/usr/sbin:/usr/bin:/apps/weka/3.7.12:/home/m/maxwell9/bin:/home/m/maxwell9/2.4.3/include 

i confirmed there file @

/home/m/maxwell9/2.4.3/include/opencv2/highgui/highgui.hpp 

just adding include path resolve compile problem. still see linker errors.. (and right way of adding include path using -i flag, path not used this..)

to compile , link program successfully, need both specify include path header files , linker path pre-compiled opencv libraries , list of libraries linked...

  1. the standard way, had installed opencv standard installation directory,by using following sequence

     sudo make install (from opencv build library)  echo '/usr/local/lib' | sudo tee -a /etc/ld.so.conf.d/opencv.conf  sudo ldconfig  printf '# opencv\npkg_config_path=$pkg_config_path:/usr/local/lib/pkgconfig\nexport pkg_config_path\n' >> ~/.bashrc    source ~/.bashrc   

the following have compiled , linked program :

g++ my_simple_script.cpp `pkg-config --libs opencv` `pkg-config --cflags opencv` 
  1. but apparently have not done that.. trying point non-standard include path. hence in case need specify include path explicitly using -i flag , pre-compiled library path -l flag , list out individual libraries might want use using -l<name_of_library>

    g++ my_simple_script.cpp -i /home/m/maxwell9/2.4.3/include -l /home/m/maxwell9/2.4.3/<your build directory name>/lib/ -lopencv_core 

(list of other opencv libraries may need have appended above command using format: -l<name of lib need>)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -