{"id":339,"date":"2022-08-30T14:59:42","date_gmt":"2022-08-30T14:59:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/opencv-error-undefined-reference-to-cvloadimage-collection-of-common-programming-errors\/"},"modified":"2022-08-30T14:59:42","modified_gmt":"2022-08-30T14:59:42","slug":"opencv-error-undefined-reference-to-cvloadimage-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/opencv-error-undefined-reference-to-cvloadimage-collection-of-common-programming-errors\/","title":{"rendered":"OPENCV error: undefined reference to &ldquo;cvLoadImage&rdquo;-Collection of common programming errors"},"content":{"rendered":"<p>I have two files:<\/p>\n<p>test.cpp :<\/p>\n<pre><code>#include \"highgui.h\"\n#include \nint main( int argc, char** argv ) {\n    IplImage* img = cvLoadImage( argv[1] );\n    cvNamedWindow( \"Example1\", CV_WINDOW_AUTOSIZE );\n    cvShowImage( \"Example1\", img );\n    cvWaitKey(0);\n    cvReleaseImage( &amp;img );\n    cvDestroyWindow( \"Example1\" );\n}\n<\/code><\/pre>\n<p>CMakeLists.txt:<\/p>\n<pre><code>cmake_minimum_required(VERSION 2.8)\nset(CMAKE_MODULE_PATH ${\/home\/jinder1s\/Documents\/project\/opencv\/FindOpenCV.make} )\nproject(hello)\nFind_package (OpenCV REQUIRED)\nif(OpenCV_FOUND)\n    add_executable (Hello test.cpp)\n    find_library(Opencv_lib \n    NAMES opencv_core opencv_highgui opencv_imgproc\n    PATHS \/usr\/local\/lib)\nendif()\n<\/code><\/pre>\n<p>this is the template for what I got.<\/p>\n<pre><code>jinder1s@jinder1s-lat-lap:~\/Documents\/project\/opencv\/tests$ cmake .\n-- Configuring done\n-- Generating done\n-- Build files have been written to: \/home\/jinder1s\/Documents\/project\/opencv\/tests\njinder1s@jinder1s-lat-lap:~\/Documents\/project\/opencv\/tests$ make\nLinking CXX executable Hello\nCMakeFiles\/Hello.dir\/test.cpp.o: In function `main':\ntest.cpp:(.text+0x1d): undefined reference to `cvLoadImage'\ntest.cpp:(.text+0x35): undefined reference to `cvNamedWindow'\ntest.cpp:(.text+0x49): undefined reference to `cvShowImage'\ntest.cpp:(.text+0x55): undefined reference to `cvWaitKey'\ntest.cpp:(.text+0x61): undefined reference to `cvReleaseImage'\ntest.cpp:(.text+0x6d): undefined reference to `cvDestroyWindow'\ncollect2: error: ld returned 1 exit status\nmake[2]: *** [Hello] Error 1\nmake[1]: *** [CMakeFiles\/Hello.dir\/all] Error 2\nmake: *** [all] Error 2\n<\/code><\/pre>\n<p>I just started learning opencv, as in this is my first code, and I just can&#8217;t seem to get it to work. I could really use some help here. Can&#8217;t see what I&#8217;m doing wrong.<\/p>\n<ol>\n<li>\n<p>I think you need to specify the namespace there. So either do a <code>using namespace cv;<\/code> up top, or <code>cv::function_name<\/code> for every function call.<\/p>\n<p>Also, this looks like OpenCV 1.x code. Is there a reason why you&#8217;re doing that instead of using OpenCV 2.x syntax? 2.x is way more stable and intuitive. For example, that load image line would just be <code>Mat img = imread(filename);<\/code> in 2.x. And you&#8217;d need <code>#include \"opencv2\/core\/core.hpp\"<\/code> and <code>using namespace cv;<\/code> up top, for 2.x.<\/p>\n<p>This cheatsheet may help.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:11:15. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have two files: test.cpp : #include &#8220;highgui.h&#8221; #include int main( int argc, char** argv ) { IplImage* img = cvLoadImage( argv[1] ); cvNamedWindow( &#8220;Example1&#8221;, CV_WINDOW_AUTOSIZE ); cvShowImage( &#8220;Example1&#8221;, img ); cvWaitKey(0); cvReleaseImage( &amp;img ); cvDestroyWindow( &#8220;Example1&#8221; ); } CMakeLists.txt: cmake_minimum_required(VERSION 2.8) set(CMAKE_MODULE_PATH ${\/home\/jinder1s\/Documents\/project\/opencv\/FindOpenCV.make} ) project(hello) Find_package (OpenCV REQUIRED) if(OpenCV_FOUND) add_executable (Hello test.cpp) find_library(Opencv_lib NAMES [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-339","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}