Note that there are some explanatory texts on larger screens.

plurals
  1. POg++ Linking Error on Mac while compiling FFMPEG
    text
    copied!<p>g++ on Snow Leopard is throwing linking errors on the following piece of code</p> <p>test.cpp</p> <pre><code>#include &lt;iostream&gt; using namespace std; #include &lt;libavcodec/avcodec.h&gt; // required headers #include &lt;libavformat/avformat.h&gt; int main(int argc, char**argv) { av_register_all(); // offending library call return 0; } </code></pre> <p>When I try to compile this using the following command</p> <pre><code>g++ test.cpp -I/usr/local/include -L/usr/local/lib \ -lavcodec -lavformat -lavutil -lz -lm -o test </code></pre> <p>I get the error Undefined symbols: "av_register_all()", referenced from: _main in ccUD1ueX.o ld: symbol(s) not found collect2: ld returned 1 exit status</p> <p>Interestingly, if I have an equivalent c code, test.c</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;libavcodec/avcodec.h&gt; #include &lt;libavformat/avformat.h&gt; int main(int argc, char**argv) { av_register_all(); return 0; } </code></pre> <p>gcc compiles it just fine</p> <pre><code>gcc test.c -I/usr/local/include -L/usr/local/lib \ -lavcodec -lavformat -lavutil -lz -lm -o test </code></pre> <p>I am using Mac OS X 10.6.5</p> <pre><code>$ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664) $ gcc --version i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664) </code></pre> <p>FFMPEG's libavcodec, libavformat etc. are C libraries and I have built them on my machine like thus:</p> <pre><code>./configure --enable-gpl --enable-pthreads --enable-shared \ --disable-doc --enable-libx264 make &amp;&amp; sudo make install </code></pre> <p>As one would expect, libavformat indeed contains the symbol av_register_all</p> <pre><code>$ nm /usr/local/lib/libavformat.a | grep av_register_all 0000000000000000 T _av_register_all 00000000000089b0 S _av_register_all.eh </code></pre> <p>I am inclined to believe g++ and gcc have different views of the libraries on my machine. g++ is not able to pick up the right libraries. Any clue?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload