Ben Kochavi
Ben Kochavi

Reputation: 293

How to resolve LINK errors due to addition of .lib files to a C++ project in Visual Studio?

I've created a new c++ project with Visual Studio Pro 2012.

I tried to add C language 1ib files,but I'm getting some LINK errors like:

Error 2 error LNK2019: unresolved external symbol _av_malloc@4 referenced in function _video_encode_example@4 D:\C-Sharp\C++ Compiling\ConsoleApplication7\ConsoleApplication7\example.obj ConsoleApplication7

On my part I went to "Properties" on my "Project Name" in the Solution Explorer, then to Linker > Input and then at the top,in Additional Dependencies I did edit and added all the .lib files:

avcodec.lib
avdevice.lib
avfilter.lib
avformat.lib
avutil.lib

Do I need to add more missing .lib files ? I looked again and these are the only .lib files I have.

I didn't change anything else in the Linker.In the VC++ I changed the Include Directories to: D:\C-Sharp\C++ Compiling\ConsoleApplication4\ConsoleApplication1\include

In the include directory there are some directories in each directory along with some header files.

The reference directories and library directories changed both to the same directory: 'D:\c++dev\ffmpeg-20130418-git-ee94362-win64-dev\lib'.In this directory there are Lib files,DEF files and some A files.

How can I resolve these errors ?

** I search in google i tried to change the SubSystem to Console but it didn't help. ** I have main function already:

#include "stdafx.h"
#include "targetver.h"

int _tmain(int argc, _TCHAR* argv[])
{

    return 0;
}

I have 8 LINK errors and error number 9 is:

Error 10 error LNK1120: 8 unresolved externals D:\C-Sharp\C++ Compiling\ConsoleApplication7\Debug\ConsoleApplication7.exe 1 1 ConsoleApplication7

What else can i do to resolve this problems ?

** EDIT **

Changed the project target to x64 now i have only two link erros:

Error 2 error LNK2019: unresolved external symbol avcodec_open referenced in function video_encode_example D:\C-Sharp\C++ Compiling\ConsoleApplication7\ConsoleApplication7\example.obj ConsoleApplication7

And

Error 3 error LNK1120: 1 unresolved externals D:\C-Sharp\C++ Compiling\ConsoleApplication7\x64\Debug\ConsoleApplication7.exe 1 1 ConsoleApplication7

Tried to make double click on them but nothing. I'm not sure what to do now.

Upvotes: 0

Views: 1990

Answers (2)

Roger Rowland
Roger Rowland

Reputation: 26259

I just spotted in your question that you're using ffmpeg libraries.

If you want to link these into a C++ project, you have to make sure that you wrap the #include statements in an extern "C" block, like this:

extern "C"
{
    #include "avformat.h"   // etc. etc.
}

This will fix the link errors by making sure that the exported function names are not mangled on import.

Upvotes: 2

lucasmrod
lucasmrod

Reputation: 260

Try including the paths of your *.lib files on:

Linker -> General -> Additional Library Directories

Upvotes: 0

Related Questions