[英]Unresolved externals in Visual C++
I'm trying to compile a solution in MS Visual Studio C++ 2012. 我正在尝试在MS Visual Studio C ++ 2012中编译解决方案。
My code uses marshallsoft AES
library. 我的代码使用marshallsoft
AES
库。
I added these for library and include paths: 我为库添加了这些,并包含路径:
C:\\aes4c\\APPS
to Configuration properties->VC++ Directories->Include Directories
C:\\aes4c\\APPS
到Configuration properties->VC++ Directories->Include Directories
C:\\aes4c\\DLLS
to Configuration properties->VC++ Directories->Library Directories
C:\\aes4c\\DLLS
到Configuration properties->VC++ Directories->Library Directories
When I compile the individual .cpp
file it compiles without problem but when I build the solution I get: 当我编译单个
.cpp
文件时,它可以毫无问题地进行编译,但是当我构建解决方案时,我得到:
------ Build started: Project: cryptest2, Configuration: Debug Win32 ------
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesAttach@8 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW@@YAHPAD0@Z)
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesEncryptFile@12 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW@@YAHPAD0@Z)
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesInitAES@20 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW@@YAHPAD0@Z)
C:\Users\ariyan\documents\visual studio 2012\Projects\cryptest2\Debug\cryptest2.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What is the problem? 问题是什么?
How Can I fix it? 我该如何解决?
My code is: 我的代码是:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "aes.h"
int EncryptFile(char *KeyBuffer, char *FileName);
int _tmain(int argc, _TCHAR* argv[])
{
EncryptFile("1234567890abcdef","c:\test.txt");
return 0;
}
int EncryptFile(char *KeyBuffer, char *FileName)
{int Code;
// attach DLL
Code = aesAttach(0, 0);
if(Code<0)
{printf("ERROR %d: Cannot attach\n", Code);
return FALSE;
}
printf("Will encrypt file in CBC mode\n");
Code = aesInitAES((char *)KeyBuffer, NULL, AES_ECB_MODE, AES_ENCRYPT, NULL);
if(Code<0)
{printf("aesInitAES fails\n");
return FALSE;
}
printf("Encrypt file...\n");
Code = aesEncryptFile(NULL, KeyBuffer, FileName);
if(Code<0)
{printf("aesEncryptFile fails\n");
return FALSE;
}
printf("%d bytes encrypted\n", Code);
return Code;
}
It's not enough to add to library path - that just tells the linker where to look for a library if and when it decides to link with it. 这是不够的,添加到库路径-这只是告诉链接到哪里寻找库,如果当它决定与它联系起来。 But you have to tell the linker to look for it in the first place.
但是您必须首先告诉链接器寻找它。 For that, mention the LIB file name in
为此,请在中提及LIB文件名
Project > Properties > Linker > Input > Additional Dependencies
项目>属性>链接器>输入>其他依赖项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.