2013-08-21 196 views
7

我使用Microsoft Visual Studio 2010,和我工作的開源ClamAV的,我的代碼如下這是產生錯誤LINK:致命錯誤LNK1181:無法打開輸入文件「libclamav.lib」

#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; 
} 
給出產生

以下錯誤 LINK:致命錯誤LNK1181:無法打開輸入文件「libclamav.lib」

親切指導我

+0

C或C++? 2013-08-21 08:11:33

+0

傳統上,UNIX世界中的libXYZ.a是Windows世界中的XYZ.lib。你似乎混合了這兩個世界。 – trojanfoe

+0

你的代碼可能沒有問題。錯誤在於你編譯它的方式。請提供一些細節。 – hivert

回答

14

你得到在Visual Studio中的LNK1181錯誤時的.lib或.obj文件在鏈接期間指定的不是在當前目錄中找到由LIBPATH鏈接器選項或LIB環境變量中指定的任何目錄指定的任何目錄。

您可以添加包含libclamav.lib庫文件到LIBPATH解決該問題的目錄(這說明可能會因您的Visual Studio版本會略有不同):

  1. 在解決方案資源管理器中,右鍵單擊項目,然後單擊屬性
  2. 屬性頁對話框,展開鏈接,然後單擊一般
  3. 其他庫目錄字段中,指定libclamav.lib所在的路徑。

LIBPATH包含空格時也會發生此錯誤。如果是這種情況,請將庫移動到不帶空格的路徑中,或在路徑周圍加上引號。

+1

我希望我能給你1000個upvotes!我正在嘗試更新舊項目,並且LIBPATH中有空格。我一直在尋找似乎是幾個小時,而其他人都沒有提出這樣的建議。我不知道它是如何在原始的開發環境中工作的!也許他們也碰巧在LIB中擁有它......無論如何,我不知道VS的moderner版本是如何處理這個問題的,但VC++ 6(別問!)並沒有優雅地失敗。 – shiser

+0

爲了防止其他人絆倒在這,我的錯誤是更基本和愚蠢的。我試圖建立在「僅項目」內。確保先建立你的依賴關係!因此,右鍵單擊您的項目文件,然後單擊生成。 – Karoh

1

您也可以通過指定DOS「8.3」格式的庫路徑來修復它。

要得到8.3的形式,這樣做(在命令行):

DIR /AD /X 

遞歸通過目錄的各個層面。

相關問題