title: Link to ffmpeg libraries using mingw c++ -> undefined reference
body: <p>I read about a lot of very similar problems here, but none of them seems
  to solve my problem. I feel that I need only a very small step to succeed...</p>
  
  <p>I have an existing c++ project and try to include some FFmpeg functions.
  When linking with MinGW on Windows OS against the FFmpeg libraries, I get always
  the error message "undefined reference to...".</p>
  
  <p>I reduced my code totally to the following sample:</p>
  
  <pre><code>// START of file simple.cpp
  #ifndef INT64_C
  #define INT64_C(c) (c ## LL)
  #define UINT64_C(c) (c ## ULL)
  #endif
  
  #include &lt;math.h&gt;
  
  #include &lt;libavutil/opt.h&gt;
  #include &lt;libavcodec/avcodec.h&gt;
  #include &lt;libavutil/channel_layout.h&gt;
  #include &lt;libavutil/common.h&gt;
  #include &lt;libavutil/imgutils.h&gt;
  #include &lt;libavutil/mathematics.h&gt;
  #include &lt;libavutil/samplefmt.h&gt;
  
  int main(int argc, char **argv){
      avcodec_register_all();
      return 0;
  }
  // END of file simple.cpp
  </code></pre>
  
  <p>I compile with:</p>
  
  <pre><code>g++ -o simple.o -c simple.cpp -std=gnu++11
  </code></pre>
  
  <p>which worked well.
  My link command is:</p>
  
  <pre><code>g++ -o simple.exe simple.o -lavcodec -std=gnu++11
  </code></pre>
  
  <p>and I get the error message:</p>
  
  <p><code>simple.o:simple.cpp:(.text+0xc): undefined reference to avcodec_register_all()</code></p>
  
  <p>So, at least the libraries are found ;-)
  I used the libraries directly from Zeranoe and I also managed to compile
  new ones from source. The error message is the same in both cases.</p>
  
  <p>A step to find the solution might be the following test (compile with gcc instead of g++):</p>
  
  <ol>
  <li><p>I rename simple.cpp to simple.c</p></li>
  <li><p>I compile with: </p>
  
  <p><code>gcc -o simple.o -c simple.c</code></p></li>
  <li><p>I link with: </p>
  
  <p><code>g++ -o simple.o -c simple.c -lavcodec</code></p></li>
  </ol>
  
  <p>And that will work!!!</p>
  
  <p>But, unfortunately, that is no solution for me, because my main program
  is definitely c++ und must be compiled using g++.</p>
  
  <p>So, what the hell is wrong here?<br>
  Is that a FFmpeg topic or is that a gcc/g++ topic?<br>
  Please, all hints are welcome.</p>
  
  <p>I already tried out all possible 'extern' and extern "C"- statements, no success.</p>