{"id":4011,"date":"2014-03-30T07:10:35","date_gmt":"2014-03-30T07:10:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/libav-linking-error-undefined-references-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:10:35","modified_gmt":"2014-03-30T07:10:35","slug":"libav-linking-error-undefined-references-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/libav-linking-error-undefined-references-collection-of-common-programming-errors\/","title":{"rendered":"Libav linking error: undefined references-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b03209651b88364978c32e2a69ad8ec8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFedech<\/p>\n<p>Here&#8217;s my problem:<\/p>\n<ul>\n<li>I built ffmpeg from source (version 1.2), the libav* libraries are in \/usr\/local\/lib and they&#8217;re static<\/li>\n<li>I&#8217;m compiling a ns3 (www.nsnam.org) module, so my only control over the linker is through the env variable LINKFLAGS<\/li>\n<li>In the source the headers are in a &#8220;extern C&#8221; block, so it&#8217;s not the usual g++ name mangling<\/li>\n<li>I set LINKFLAGS=&#8221;-I\/usr\/local\/include\/libavformat -I\/usr\/local\/include\/libavcodec -I\/usr\/local\/include\/libavutil -L\/usr\/local\/lib -lavformat -lavcodec -lavutil&#8221;, and the linker can&#8217;t seem to find any of the libav* functions I call (I get a lot of &#8220;undefined reference&#8221; and then &#8220;collect2: error: ld returned status 1&#8221;<\/li>\n<\/ul>\n<p>Can anyone help me? Thanks&#8230;<\/p>\n<p>edit: here are a few of the undefined reference messages:<\/p>\n<pre><code>    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_guess_format'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_read_frame'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_write_header'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_interleaved_write_frame'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_find_stream_info'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_register_all'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_init_packet'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_alloc_context'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_dump_format'\n    .\/libns3.14.1-qoe-monitor-debug.so: undefined reference to `avio_close'\n<\/code><\/pre>\n<p>edit2: here is the message I get after &#8220;build failed&#8221;:<\/p>\n<pre><code>-&gt; task in 'scratch-simulator' failed (exit status 1): \n{task 53952272: cxxprogram scratch-simulator.cc.1.o -&gt; scratch-simulator}\n['\/usr\/bin\/g++', '-I\/usr\/local\/include\/libavcodec', '-I\/usr\/local\/include\/libavformat\/',\n '-I\/usr\/local\/include\/libavutil\/', '-L\/usr\/local\/lib', '-I\/usr\/local\n\/include\/libavcodec', '-I\/usr\/local\/include\/libavformat\/', '-I\/usr\/local\/include\n\/libavutil\/', '-L\/usr\/local\/lib', '-pthread', '-pthread', '-Wl,-z,relro', \n'scratch\/scratch-simulator.cc.1.o', '-o', '\/home\/fede\/Thesis\/ns-allinone-3.14.1\n\/ns-3.14.1\/build\/scratch\/scratch-simulator', '-Wl,-Bstatic', '-Wl,-Bdynamic', \n'-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',\n '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',\n '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', \n'-L.', '-L.', '-L.', '-L.', '-L.', '-L\/usr\/lib', '-lns3.14.1-test-debug', '-lns3.14.1-\ncsma-layout-debug', '-lns3.14.1-point-to-point-layout-debug', '-lns3.14.1-netanim-\ndebug', '-lns3.14.1-lte-debug', '-lns3.14.1-spectrum-debug', '-lns3.14.1-antenna-\ndebug', '-lns3.14.1-aodv-debug', '-lns3.14.1-dsdv-debug', '-lns3.14.1-dsr-debug', \n'-lns3.14.1-mesh-debug', '-lns3.14.1-olsr-debug', '-lns3.14.1-csma-debug', '-lns3.14.1-\nwimax-debug', '-lns3.14.1-applications-debug', '-lns3.14.1-virtual-net-device-debug', \n'-lns3.14.1-uan-debug', '-lns3.14.1-energy-debug', '-lns3.14.1-flow-monitor-debug', \n'-lns3.14.1-nix-vector-routing-debug', '-lns3.14.1-tap-bridge-debug', '-lns3.14.1-\nvisualizer-debug', '-lns3.14.1-internet-debug', '-lns3.14.1-bridge-debug', '-lns3.14.1-\npoint-to-point-debug', '-lns3.14.1-mpi-debug', '-lns3.14.1-wifi-debug', '-lns3.14.1-\nbuildings-debug', '-lns3.14.1-propagation-debug', '-lns3.14.1-mobility-debug', \n'-lns3.14.1-config-store-debug', '-lns3.14.1-tools-debug', '-lns3.14.1-stats-debug',\n '-lns3.14.1-emu-debug', '-lns3.14.1-topology-read-debug', '-lns3.14.1-network-debug', \n'-lns3.14.1-qoe-monitor-debug', '-lns3.14.1-core-debug', '-lrt', '-lgsl', \n'-lgslcblas', '-lm', '-ldl', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', \n'-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', \n'-lpango-1.0', '-lfreetype', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lxml2', \n'-lpython2.7']\n<\/code><\/pre>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/38c765bcba6fa695921d2aa542eee09a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMultimedia Mike<\/p>\n<p>Thanks for posting the output of the build system. As an aside, what build system is that? Is it Scons?<\/p>\n<p>I studied that build output (I assume that all the individual elements in the array or concatenated into a string and executed). I&#8217;m not seeing <code>-lavformat<\/code> anywhere. I did a cmd-f search within my browser in order to confirm this. Why doesn&#8217;t it show up? Are you sure that all the contents of LINKFLAGS is making it into that output?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e57bdb96b301c5d83c7e16eec9c0f071?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJason C<\/p>\n<p>The libraries are C. The library headers don&#8217;t include an extern &#8220;C&#8221; when compiled as C++. Do this in your C++ source:<\/p>\n<pre><code>extern \"C\" { \n#include  \n#include \n}\n<\/code><\/pre>\n<p>Or, more generically, for mixed C and C++ source:<\/p>\n<pre><code>#ifdef __cplusplus\nextern \"C\" {\n#endif\n#include  \n#include \n#ifdef __cplusplus \n}\n#endif\n<\/code><\/pre>\n<p>And you should be fine.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Fedech Here&#8217;s my problem: I built ffmpeg from source (version 1.2), the libav* libraries are in \/usr\/local\/lib and they&#8217;re static I&#8217;m compiling a ns3 (www.nsnam.org) module, so my only control over the linker is through the env variable LINKFLAGS In the source the headers are in a &#8220;extern C&#8221; block, so it&#8217;s not the usual [&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-4011","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4011","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=4011"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4011\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}