C++ 链接:致命错误 LNK1181:无法打开输入文件“libclamav.lib”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18352101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:55:02  来源:igfitidea点击:

LINK : fatal error LNK1181: cannot open input file 'libclamav.lib'

c++c

提问by WiXXeY

I am using Microsoft Visual Studio 2010, and i am working on open source Clamav, my code is given below which is generating an error

我正在使用 Microsoft Visual Studio 2010,并且我正在开发开源 Clamav,下面给出了我的代码,它产生了一个错误

#include <stdio.h>
#include <stdlib.h>  
#include <string.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <clamav.h>


int main(int argc, char **argv)
{
int fd, ret;
unsigned long int size = 0;
unsigned int sigs = 0;
long double mb;
const char *virname;
struct cl_engine *engine;


if(argc != 2) {
printf("Usage: %s file\n", argv[0]);
return 2;
}

if((fd = open(argv[1], O_RDONLY)) == -1) {
printf("Can't open file %s\n", argv[1]);
return 2;
}

if((ret = cl_init(CL_INIT_DEFAULT)) != CL_SUCCESS) {
printf("Can't initialize libclamav: %s\n", cl_strerror(ret));
return 2;
}

if(!(engine = cl_engine_new())) {
printf("Can't create new engine\n");
return 2;
}

/* load all available databases from default directory */
if((ret = cl_load(cl_retdbdir(), engine, &sigs, CL_DB_STDOPT)) != CL_SUCCESS) {
printf("cl_load: %s\n", cl_strerror(ret));
close(fd);
    cl_engine_free(engine);
return 2;
}

printf("Loaded %u signatures.\n", sigs);

/* build engine */
if((ret = cl_engine_compile(engine)) != CL_SUCCESS) {
printf("Database initialization error: %s\n", cl_strerror(ret));;
    cl_engine_free(engine);
close(fd);
return 2;
}

/* scan file descriptor */
if((ret = cl_scandesc(fd, &virname, &size, engine, CL_SCAN_STDOPT)) == CL_VIRUS) {
printf("Virus detected: %s\n", virname);
} else {
if(ret == CL_CLEAN) {
    printf("No virus detected.\n");
} else {
    printf("Error: %s\n", cl_strerror(ret));
    cl_engine_free(engine);
    close(fd);
    return 2;
}
}
close(fd);

/* free memory */
cl_engine_free(engine);

/* calculate size of scanned data */
mb = size * (CL_COUNT_PRECISION / 1024) / 1024.0;
printf("Data scanned: %2.2Lf MB\n", mb);

return ret == CL_VIRUS ? 1 : 0;
}

the following error is generated LINK : fatal error LNK1181: cannot open input file 'libclamav.lib'

生成以下错误链接:致命错误 LNK1181:无法打开输入文件“libclamav.lib”

kindly guide me

请指导我

回答by Daniel Martín

You get an LNK1181 error in Visual Studio when the .lib or .obj files that are specified during linking are not found in the current directory, any of the directories that are specified by the LIBPATHlinker option, or any of the directories that are specified in the LIBenvironment variable.

如果在链接期间指定的 .lib 或 .obj 文件在当前目录、LIBPATH链接器选项指定的任何目录或的LIB环境变量。

You may add the directory that contains libclamav.liblibrary file to the LIBPATHto resolve the problem (this instructions may vary a bit depending on your Visual Studio version):

您可以将包含libclamav.lib库文件的目录添加到LIBPATH以解决问题(此说明可能会因您的 Visual Studio 版本而有所不同):

  1. In Solution Explorer, right-click the project, and then click Properties.
  2. In the Property Pagesdialog box, expand Linker, and then click General.
  3. In the Additional Library Directoriesfield, specify the path where libclamav.libresides.
  1. 在解决方案资源管理器中,右键单击该项目,然后单击“属性”
  2. 在“属性页”对话框中,展开“链接器”,然后单击“常规”
  3. 附加库目录字段中,指定libclamav.lib所在的路径。

The error can also happen when the LIBPATHcontains spaces. If that's the case, move the library to a path without spaces or put quotation marks around the path.

LIBPATH包含空格时也可能发生错误。如果是这种情况,请将库移动到没有空格的路径或在路径周围加上引号。

回答by Pierre

You can also fix it by specifying the library path in DOS "8.3" format.

您也可以通过指定 DOS“8.3”格式的库路径来修复它。

To get the 8.3 form, do (at the command line):

要获得 8.3 形式,请执行(在命令行中):

DIR /AD /X

recursively through every level of the directories.

递归地遍历目录的每一层。