1

I'm making a C++ program and I want to use FFmpeg pre-built for x64, which is a C-compiled library. I'm using this code in order to include its header:

extern "C" {
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"

    #pragma comment (lib,"G:/Documents/ffmpeg/lib/avcodec.lib")
    #pragma comment (lib,"G:/Documents/ffmpeg/lib/avformat.lib")
}

I'm then calling the symbols like I would do for a normal function, for example with av_interleaved_write_frame(out->formatContext, &packet);

However, when I try to compile it with Visual Studio 2015's built-in C++ compiler, I get a lot of error like

Error   LNK2019 unresolved external symbol _av_write_trailer referenced in function "void __cdecl closeArenaVideo(struct VideoOutput *)" (?closeArenaVideo@@YAXPAUVideoOutput@@@Z)  Sparta2 c:\Users\Théo\documents\visual studio 2015\Projects\Sparta2\Sparta2\video.obj   

for basically any of the symbols I'm refering to.

I tried to import everything in Visual Studio, to compile with command-line, to manually put FFmpeg's libraries in the default libraries path, without success.

Thank you in advance!

JustPingo
  • 13
  • 6
  • Check [this answer](http://stackoverflow.com/a/11701737/868014) and its update at the bottom related to 32/64 lib confusion, it might be your case too. – Roman R. Feb 25 '16 at 21:44
  • Thank you very much, that is indeed the problem! You can make a proper answer if you want to, I will mark it as accepted. – JustPingo Feb 25 '16 at 21:51

1 Answers1

1

A typical problem which is hard to understand from quoted linker errors is the problem of referencing wrong .lib files, esp Win32 platform libraries in x64 build and vice versa. The names might be correct, but the set is wrong and then linker takes the #pragma references but ignores the content.

You should make sure that your build platform matches the bitness of referenced library files. This answer has minimalistic project which does build well and you can compare code/references to what you use, and it also mentions bitness problem as well in the very bottom and comments to the answer.

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158