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...
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...".
I reduced my code totally to the following sample:
// START of file simple.cpp
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <math.h>
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
#include <libavutil/channel_layout.h>
#include <libavutil/common.h>
#include <libavutil/imgutils.h>
#include <libavutil/mathematics.h>
#include <libavutil/samplefmt.h>
int main(int argc, char **argv){
avcodec_register_all();
return 0;
}
// END of file simple.cpp
I compile with:
g++ -o simple.o -c simple.cpp -std=gnu++11
which worked well. My link command is:
g++ -o simple.exe simple.o -lavcodec -std=gnu++11
and I get the error message:
simple.o:simple.cpp:(.text+0xc): undefined reference to avcodec_register_all()
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.
A step to find the solution might be the following test (compile with gcc instead of g++):
I rename simple.cpp to simple.c
I compile with:
gcc -o simple.o -c simple.c
I link with:
g++ -o simple.o -c simple.c -lavcodec
And that will work!!!
But, unfortunately, that is no solution for me, because my main program is definitely c++ und must be compiled using g++.
So, what the hell is wrong here?
Is that a FFmpeg topic or is that a gcc/g++ topic?
Please, all hints are welcome.
I already tried out all possible 'extern' and extern "C"- statements, no success.