2

I am using git version of ffmpeg( renewed after old version succesful using) , when i try to compile my project i get

 /usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:376: undefined reference to `swr_is_initialized'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:222: undefined reference to `swr_is_initialized'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_init_resample':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:163: undefined reference to `swr_init'
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:169: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:236: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_flush_resample':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:117: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:408: undefined reference to `swr_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_flush':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:557: undefined reference to `swr_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_close':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:579: undefined reference to `swr_free'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_init':
/home/user/projects/ffmpleglast/ffmpeg/libavcodec/opusdec.c:629: undefined reference to `swr_alloc'

Seems to be version conflict? but how to delete wrong libs? they seem to be todays build.

ls -l /usr/local/lib
-rw-r--r-- 1 root root  136509684 may   29 14:47 libavcodec.a
-rw-r--r-- 1 root root    1853574 may   29 14:47 libavdevice.a
-rw-r--r-- 1 root root    9689456 may   29 14:47 libavfilter.a
-rw-r--r-- 1 root root   46282270 may   29 14:47 libavformat.a
-rw-r--r-- 1 root root    2092250 may   29 14:47 libavutil.a
-rw-r--r-- 1 root root      67942 may   12 11:29 libBasicUsageEnvironment.a
-rw-r--r-- 1 root root    2200164 apr.  10 10:11 libfftw3.a
-rwxr-xr-x 1 root root        872 apr.  10 10:11 libfftw3.la
-rw-r--r-- 1 root root      94188 may   12 11:29 libgroupsock.a
-rw-r--r-- 1 root root    2236084 may   12 11:29 libliveMedia.a
-rw-r--r-- 1 root root     546506 may   29 14:47 libswresample.a
-rw-r--r-- 1 root root    4813716 may   29 14:47 libswscale.a
-rw-r--r-- 1 root root      14588 may   12 11:29 libUsageEnvironment.a
user3177342
  • 55
  • 2
  • 10
  • so did you solve this? I'm getting the same error when building my project as static executable – user2212461 Jul 22 '14 at 08:50
  • I was missing the extern "C" part around those particular #includes. I'm not sure why I need them on those and not on other includes, but that did the trick. – LawfulEvil Jan 05 '15 at 17:55

2 Answers2

3

I was getting these same kinds of errors when I was building a DLL which tried to pull in the ffmpeg DLLs.

I was missing the extern C statement around the ffmpeg include files :

extern "C"
{
#include "include\libavcodec\avcodec.h"
#include "include\libavformat\avformat.h"
#include "include\libavformat\avio.h"
#include "include\libswscale\swscale.h"
#include "include\libavutil\dict.h"
#include "include\libavutil\frame.h"
}

I also found that I needed to add the DLLs to the solution as dependencies or use the pragma statements to get it to include.

#pragma comment(lib, "..\\..\\..\\..\\contrib\\ffmpeg\\lib\\avformat.lib")
#pragma comment(lib, "..\\..\\..\\..\\contrib\\ffmpeg\\lib\\swscale.lib")
#pragma comment(lib, "..\\..\\..\\..\\contrib\\ffmpeg\\lib\\avutil.lib")

This was on windows and simply tells VS that the lib files specified detail the interfaces for DLLs in those same locations. You won't need that on linux as your -lavformat etc statements should cover it, but I suspect you might need the extern C part.

If its still not helping, maybe use verbose mode on the compile/link so you can see what's coming in from which locations.

LawfulEvil
  • 2,267
  • 24
  • 46
  • thank you very much for this extern "C", almost died figuring out linking ffmpeg using cmake to my cpp class – sancheese Jan 13 '17 at 12:33
1

You probably have also ffmpeg installed in system (in /usr/lib and /usr/include). Try to force include path with -I parameter (/usr/local/include) and library path with -L parameter (/usr/local/lib)

Lukasz
  • 186
  • 3
  • i use Code::Blocks as it is comfort. So in build target search directories i have "include /usr/local/include /usr/include/ImageMagick/ /home/user/projects/COPY2/sglplayer" in linker only "/usr/local/lib" but the compiling errors are the same. I finded libavcodec.so.53.35.0 in /usr/lib/x86_64-linux-gnu but i think i am linking to it in my project. – user3177342 May 29 '14 at 12:14