0

I'm trying to compile program but getting strange error don't know why.

> c++ src/main.cpp.o -o test -lavformat -lavcodec -lavdevice -lavutil -lswscale -lpthread /usr/bin/ld: src/main.cpp.o: undefined reference to symbol 'avcodec_receive_packet@@LIBAVCODEC_57' //usr/local/lib/libavcodec.so.57: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

But When I find inspect /usr/local/lib/libavcodec.so.57 with nm, I get following output

> nm /usr/local/lib/libavcodec.so.57 | grep avcodec_receive_packet 0000000000630590 T avcodec_receive_packet

It's strange why c++ couldn't detect avcodec_receive_packet

Update: Since I'm using C from C++, C code is enclosed with extern keyword

extern "C" {
#include <libavutil/opt.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
twid
  • 6,368
  • 4
  • 32
  • 50
  • 1
    Possible duplicate of ["undefined reference to" errors when linking static C library with C++ code](https://stackoverflow.com/questions/18877437/undefined-reference-to-errors-when-linking-static-c-library-with-c-code) – user0042 Dec 09 '17 at 15:39
  • Also see the FFmpeg FAQ regarding using the API from a C++ application: http://ffmpeg.org/faq.html#I_0027m-using-FFmpeg-from-within-my-C_002b_002b-application-but-the-linker-complains-about-missing-symbols-which-seem-to-be-available_002e – Ronald S. Bultje Dec 09 '17 at 15:56
  • @user0042 I am not using static library but shared one. – twid Dec 09 '17 at 17:19
  • That doesn't actually matter. The problem is that your `main.cpp` was compiled using the c++ compiler while `libavcodec` was compiled using the c compiler. – user0042 Dec 09 '17 at 17:32

0 Answers0