0

I've compiled libav following the instructions in their README and INSTALL instructions.

Now I'm trying to follow this example from within Qt creator.

I've figured out how to include the libraries I need in the project file:

LIBS += \
/usr/local/lib/libavformat.a \
/usr/local/lib/libavutil.a

and also that I need to wrap the include directives in an extern:

extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
}

The problem is that when I try and compile my Qt project, I just get heaps (about 700 or so) of messages about an "undefined reference to 'av_new_packet'" from functions throughout the library.

What else do I need to do to get this to work?

Update:

I noticed - just as my eyes were getting blurry from being up so late - that the errors were in header files located in the download folder? This is the folder I had run the configure and make commands which then produced the libav*.a libraries in /usr/local/lib that I'm linking to. Is this right? How do I fix if it isn't?

HorusKol
  • 8,375
  • 10
  • 51
  • 92
  • Try `readelf -s /usr/local/lib/libavformat.so | grep av_new_packet`, and check if the symbol is **defined** in it, and I don't recommend linking to static libraries in this case, you can also violate licensing terms. And I believe you are missing `libavcodec.a|so` too... – Iharob Al Asimi Mar 12 '15 at 12:33
  • it looks like it is defined in libavcodec.a (and is not defined in libavformat.a) - i included that in the Qt LIBS definition, but I'm still getting the error. Also - you'll have to forgive me as I'm kind of new to C++ - what is wrong with static libraries "in this case"? – HorusKol Mar 12 '15 at 13:01
  • 3
    There's nothing wrong with static libraries, it's not a C++ question, but a legal question. In a nutshell, when using LGPL code, your user must be able to relink your closed-source code with LGPL libraries that he provides. So, when you use static linking, you need to provide a `.lib` with the objects for all of the closed-source code, that can be then statically linked to the LGPL libraries. – Kuba hasn't forgotten Monica Mar 12 '15 at 13:15
  • `ffmpeg()` experimented a lot of changes recently so you need to check that your `libav*` versions are compatible with that of the tutorial. Also, the other reason why I said that static libraries are not a good idea is because if you link to the static libraries all the code in them will be merged with your code in a single binary file, so you might not want that. To fix that just change the suffix from `.a` to `.so`. – Iharob Al Asimi Mar 12 '15 at 13:32
  • and how do I check compatibility of the tutorial? there is no version information listed at https://libav.org/doxygen/master/metadata_8c-example.html – HorusKol Mar 12 '15 at 13:39
  • @KubaOber I see your point re: legal vs C++ - what I meant to say is that I've never had to consider the effects of distribution of code (like with C++ software) as I've only ever written PHP and other applications that were not distributed – HorusKol Mar 12 '15 at 13:42

1 Answers1

0

Only part of an answer, but I ended up removing the built-from-source libraries and download the libav*-dev packages for Ubuntu 14.04.

I could then link against the shared object files installed at

 /usr/lib/x86_64-linux-gnu/libavformat.so 

and

 /usr/lib/x86_64-linux-gnu/libavutil.so

This removed the problems - possibly because the Ubuntu release is pegged at an older release than what I was building from.

HorusKol
  • 8,375
  • 10
  • 51
  • 92