Reputation: 2673
I've built a shared library which references the FFMPEG
libraries. I've having a tough time to link the final application. I've fiddled for hours with library order but no joy.
g++ -o testVideoTranscode testVideoTranscode.o /usr/lib/libstdc++.so.6 -L../../../lib3p -lavutil -lswresample -lavcodec -L../../../lib -ldvsutils -ldvscfg -ldvstc -lstdc++ -lmch264dec -lfreeimage -lpthread
../../../lib/libdvstc.so: undefined reference to `sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
../../../lib/libdvstc.so: undefined reference to `av_frame_alloc()'
../../../lib/libdvstc.so: undefined reference to `avcodec_close(AVCodecContext*)'
etc etc
For example, one missing symbol, av_frame_alloc()
, is correctly in the ibavutil.so
library (albeit in a non-standard location):
nm -D ../../../lib3p/libavutil.so | grep av_frame_alloc
00021360 T av_frame_alloc
My library, libdvstc.so
, correctly shows the reference to the symbol and the file:
nm -D --demangle ../../../lib/libdvstc.so | grep av_frame_alloc
U av_frame_alloc()
ldd ../../../lib/libdvstc.so
linux-gate.so.1 => (0xb77c3000)
libavutil.so.55 => /mnt/swdevel/DVStor/source_build/lib3p/libavutil.so.55 (0xb772f000)
libswresample.so.2 => /mnt/swdevel/DVStor/source_build/lib3p/libswresample.so.2 (0xb7714000)
libavcodec.so.57 => /mnt/swdevel/DVStor/source_build/lib3p/libavcodec.so.57 (0xb623f000)
libstdc++.so.5 => /usr/local/dvstor/lib/libstdc++.so.5 (0xb616f000)
libm.so.6 => /lib/libm.so.6 (0xb6144000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb6126000)
libc.so.6 => /lib/libc.so.6 (0xb5f8f000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb5f74000)
librt.so.1 => /lib/librt.so.1 (0xb5f6b000)
libdl.so.2 => /lib/libdl.so.2 (0xb5f65000)
libz.so.1 => /lib/libz.so.1 (0xb5f51000)
/lib/ld-linux.so.2 (0x00871000)
Its all there. I'm stuck...
Upvotes: 1
Views: 1364
Reputation: 313
Alternate method (http://soledadpenades.com/2009/11/24/linking-with-ffmpegs-libav/) is to compile by linking to ffmpeg libraries in following format:
gcc -o main.o main.c `pkg-config --cflags --libs libavformat libavutil`
Upvotes: 0
Reputation: 11174
Use extern "C" around the include statements of the FFmpeg headers:
extern "C" {
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
[etc]
}
Most libraries do that for you, but FFmpeg doesn't, for some philosophical reason.
Upvotes: 4