{"id":330,"date":"2022-08-30T14:59:33","date_gmt":"2022-08-30T14:59:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/build-error-with-calcopticalflowfarneback-function-opencv-c-language-eclipse-macosx-collection-of-common-programming-errors\/"},"modified":"2022-08-30T14:59:33","modified_gmt":"2022-08-30T14:59:33","slug":"build-error-with-calcopticalflowfarneback-function-opencv-c-language-eclipse-macosx-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/build-error-with-calcopticalflowfarneback-function-opencv-c-language-eclipse-macosx-collection-of-common-programming-errors\/","title":{"rendered":"Build Error with CalcOpticalFlowFarneback Function -&gt; OpenCV -&gt; C Language &#8211; Eclipse -&gt; MacOSX-Collection of common programming errors"},"content":{"rendered":"<p>&#8220;undefined symbol&#8221; means that you have not linked against the proper library, or you have, but the library is for the wrong architecture (e.g. a 32-bit library while your machine is 64-bit).<\/p>\n<p>You need to check the linking flags and paths, and the library installation path.<\/p>\n<p>If you can get the linker log in Eclipse, and\/or the command line that got passed to the linker, you can repeat the linking command from a terminal and see if you get a more helpful message (such as &#8220;library not found&#8221;). Or you can try running the <code>make<\/code> command from the terminal and do the same.<\/p>\n<p>Editing the Makefile, you might find that some commands are prepended with the &#8220;@&#8221; symbol, which prevents them from being output (their output is visible, the command itself is not). You can usually safely remove the @&#8217;s and get a more verbose output.<\/p>\n<p>Another possibility is that there is a name mangling error, and the &#8220;_&#8221; prefix to the function should not be there. I am not too familiar with Eclipse though, so I can&#8217;t follow you there. But see e.g. http:\/\/www.eclipse.org\/forums\/index.php\/m\/783606\/ ; you <em>might<\/em> have built OpenCV with the wrong options, so that now it is not compatible with your code. Which is strange, seeing as how you call other OpenCV functions without problems; but maybe you built OpenCV in two steps?<\/p>\n<p>In general (this is not limited to OpenCV!) you will have a build command such as<\/p>\n<pre><code>gcc -I\/usr\/local\/include\/opencv -L\/usr\/local\/lib main.c -o Cattura_foto2 \\\n-lopencv_core.2.4.3 \\\n-lopencv_imgproc.2.4.3 \\\n-lopencv_highgui.2.4.3 \\\n-lopencv_gpu.2.4.3\n<\/code><\/pre>\n<p>and an error complaining of an undefined symbol:<\/p>\n<pre><code>Undefined symbols for architecture x86_64: \"_cvCalcOpticalFlowFarneback\"\n<\/code><\/pre>\n<p>This means that you are linking with the libraries openvc_core.2.4.3 etc. and the linker cannot find the symbol &#8220;_cvCalcOpticalFlowFarneback&#8221;.<\/p>\n<p>Locate those libraries on your computer, and run (from Terminal) the following command against all the libraries you found. <strong>Note: your path will probably be different. I have \/usr\/lib64<\/strong>.<\/p>\n<pre><code>for lib in \/usr\/lib64\/libopencv_*; do \n    echo \"Examining $lib...\"\n    strings $lib | grep -i cvCalcOpticalFlowFarneback\ndone\n<\/code><\/pre>\n<p>You ought to see something like:<\/p>\n<pre><code>Examining \/usr\/lib\/libopencv_pippo_pluto...\nExamining \/usr\/lib\/libopencv_blah_blah...\n...\nExamining \/usr\/lib64\/libopencv_video.so...\ncvCalcOpticalFlowFarneback\ncvCalcOpticalFlowFarneback\nExamining \/usr\/lib64\/libopencv_video.so.2.4...\ncvCalcOpticalFlowFarneback\ncvCalcOpticalFlowFarneback\nExamining \/usr\/lib64\/libopencv_video.so.2.4.3...\ncvCalcOpticalFlowFarneback\ncvCalcOpticalFlowFarneback\n<\/code><\/pre>\n<p>The reason for the multiple matches is that libraries exist in multiple symbolic copies.<\/p>\n<p>To be sure, let&#8217;s inspect the library:<\/p>\n<pre><code>nm -D \/usr\/lib64\/libopencv_video.so.2.4 | grep Farneback\n\n0000000000027e50 T cvCalcOpticalFlowFarneback\n<\/code><\/pre>\n<p>Now we know two important things:<\/p>\n<ol>\n<li>The symbol is <em>really<\/em> called <code>cvCalcOpticalFlowFarneback<\/code>. Your GCC is complaining it doesn&#8217;t find the symbol <code>_cvCalcOpticalFlowFarneback<\/code>, with an underscore. You either built the library incorrectly or you are missing a <code>-fno-leading-underscore<\/code> option to GCC.<\/li>\n<\/ol>\n<p>But if that were the case, <strong>no OpenCV2 symbols<\/strong> at all would be recognized. So, I&#8217;m betting on #2:<\/p>\n<ol>\n<li>The symbol is in <strong>libopencv_video.so.2.4.3<\/strong>, and there is no reference to that library in your build command! You ought to have <strong>-lopencv_video.2.4.3<\/strong> or something like that. Verify your makefile and options.<\/li>\n<\/ol>\n<p>Let me know how it goes &#8211; and <em>in bocca al lupo<\/em>.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:08:22. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>&#8220;undefined symbol&#8221; means that you have not linked against the proper library, or you have, but the library is for the wrong architecture (e.g. a 32-bit library while your machine is 64-bit). You need to check the linking flags and paths, and the library installation path. If you can get the linker log in Eclipse, [&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-330","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/330","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=330"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/330\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}