[Libav-user] Linker error libswresample

Davide Caresia caresia.davide at gmail.com
Thu Aug 6 16:41:33 CEST 2015

I'm trying to set-up a function, using the ffmpeg c api 2.7.2, to re-sample
a stream (AVStream format) to fixed (1channel - u8 sample) format.

I'm using ffmpeg libswresample library, but when I try to compile, I get a
linker error that is strictly connected to swresample functions.

Let me post the code:
double *resample8(AVFrame *frame, int size, AVCodec* codec){

    /* initialization of the output array */
    double *out = new double[size];
    /* create resampling context */
    struct SwrContext *resampleContext;
    resampleContext = swr_alloc();
    if (!resampleContext) {
fprintf(stderr, "Could not allocate resampler context\n");
return NULL;

    /* set options */
    av_opt_set_int(resampleContext, "in_channel_layout",
*(codec->channel_layouts), 0);
    av_opt_set_sample_fmt(resampleContext, "in_sample_fmt",
*(codec->sample_fmts), 0);

    av_opt_set_int(resampleContext, "out_channel_layout",
    av_opt_set_sample_fmt(resampleContext, "out_sample_fmt",

    /* initialize the resampling context */
    if (swr_init(resampleContext) < 0) {
fprintf(stderr, "Failed to initialize the resampling context\n");
return NULL;

    return NULL;


Here is the inclusion:
#ifdef __cplusplus
extern "C"
#endif // __cplusplus
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
    #include <libavutil/opt.h>
    #include <libavutil/channel_layout.h>
    #include <libavutil/samplefmt.h>
    #include <libswresample/swresample.h>
#ifdef __cplusplus
} // end extern "C".
#endif // __cplusplus

And here is the error I get, compiling with netbeans 8.0.2, g++
(additional g++ commands: -lavcodec -lavformat -lavutil -lswresample
-lfftw3 -lm)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS=
make[1]: ingresso nella directory
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk
make[2]: ingresso nella directory
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o
build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/audiosync
build/Debug/GNU-Linux-x86/dataReader.o build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/tansforms.o build/Debug/GNU-Linux-x86/tognuplot.o
 -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm
build/Debug/GNU-Linux-x86/dataReader.o: nella funzione "resample8(AVFrame*,
int, AVCodec*)":
riferimento non definito a "av_opt_set_sample_fmt"
riferimento non definito a "av_opt_set_sample_fmt"
/usr/local/lib/libswresample.so: riferimento non definito a
"av_calloc at LIBAVUTIL_54"
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:65: set di istruzioni per l'obiettivo
"dist/Debug/GNU-Linux-x86/audiosync" non riuscito
make[2]: *** [dist/Debug/GNU-Linux-x86/audiosync] Errore 1
make[2]: uscita dalla directory
nbproject/Makefile-Debug.mk:62: set di istruzioni per l'obiettivo
".build-conf" non riuscito
make[1]: *** [.build-conf] Errore 2
make[1]: uscita dalla directory
nbproject/Makefile-impl.mk:39: set di istruzioni per l'obiettivo
".build-impl" non riuscito
make: *** [.build-impl] Errore 2

BUILD FAILED (exit value 2, total time: 5s)

here is the linker configuration

I searched for any clue about the linker error, and I found that it could
be caused by multiple versions of ffmpeg installed. I removed ubuntu (I'm
using 15.04) base installation of ffmpeg and installed ffmpeg 2.7.2 from
the tar downloaded by ffmpeg.org

I can't seem to find a solution at the moment, can anyone help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150806/9eb95ba2/attachment.html>

More information about the Libav-user mailing list