如何解决由于在Visual Studio中添加.lib文件到C ++项目的LINK错误? [英] How to resolve LINK errors due to addition of .lib files to a C++ project in Visual Studio?
问题描述
我使用Visual Studio Pro 2012创建了一个新的c ++项目。
我试图添加C语言 1ib
文件,但我收到一些 LINK 错误:
错误2错误LNK2019:未解析的外部符号_av_malloc @ 4在函数_video_encode_example @ 4中引用D:\C-Sharp\C ++ Compiling\ConsoleApplication7\ConsoleApplication7\example.obj ConsoleApplication7
在我的部分,我在解决方案资源管理器
中的项目名称 ,然后到 Linker>然后在附加依赖关系中,我已编辑,并添加了所有
.lib
档案:
avcodec.lib
avdevice.lib
avfilter.lib
avformat.lib
avutil.lib
我需要添加更多缺少的.lib文件吗?我再次查看,这些是我唯一的.lib文件。
我没有改变任何其他的链接器。在VC ++我改变了包括目录: D:\ C-Sharp\C ++ Compiling\ConsoleApplication4\ConsoleApplication1\include
include
目录每个目录中都有一些目录以及一些头文件。
参考目录和库目录已更改两个到同一目录:'D:\c ++ dev\ffmpeg-20130418-git-ee94362-win64-dev\lib'.在此目录中有 Lib
文件, DEF
文件和一些 A
文件。
如何解决这些错误?
**我在google中搜索我试图将子系统更改为控制台,但它没有帮助。
**我已经有主要功能:
#includestdafx.h
#include targetver.h
int _tmain(int argc,_TCHAR * argv [])
{
return 0;
}
我有8个LINK错误,错误编号9是:
错误10错误LNK1120:8未解析的外部D:\C-Sharp\C ++ Compiling\ConsoleApplication7\Debug\ConsoleApplication7.exe 1 1 ConsoleApplication7
我还能做些什么来解决这个问题?
** EDIT **
将项目目标更改为x64现在我只有两个链接错误:
错误2错误LNK2019:未解析的外部符号avcodec_open在函数video_encode_example中引用D:\C -Sharp \C ++ Compiling\ConsoleApplication7\ConsoleApplication7\example.obj ConsoleApplication7
和
错误3错误LNK1120:1未解析的外部D:\C-Sharp\C ++ Compiling\ConsoleApplication7\x64\Debug\ConsoleApplication7.exe 1 1 ConsoleApplication7
试图双击它们,但什么也没有。我现在不知道该怎么办。
我在你的问题中发现你使用ffmpeg库。 / p>
如果你想将这些链接到一个C ++项目,你必须确保你包装 #include
语句在 externC
块中,像这样:
extern C
{
#includeavformat.h//等等。
}
这将通过确保导入的函数名在导入时不会被破坏来修复链接错误。
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.
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.
这篇关于如何解决由于在Visual Studio中添加.lib文件到C ++项目的LINK错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!