我已經掌握了libarchive,並在build instructions之後的Windows和Linux上構建了這些示例。在Qt中使用libarchive - 構建錯誤
我現在想在我的項目中使用這個庫,這是基於Qt的,所以我使用Qt創建器。我已經在我的pro文件中添加了libarchive的include路徑,但是當我編譯時,我收到錯誤,提示「undefined reference to'imp _archive_read_new'」等等。
這是我的時刻代碼:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "archive.h"
#include "archive_entry.h"
cTarFileManager::cTarFileManager()
{
struct archive *a;
struct archive_entry *entry;
int r;
int64_t entry_size;
a = archive_read_new();
archive_read_support_compression_none(a);
archive_read_support_format_tar(a);
r = archive_read_open_filename(a, "0000.tar", 1024);
if (r != ARCHIVE_OK)
{
printf("archive not found");
}
else
{
while (archive_read_next_header(a, &entry) == ARCHIVE_OK)
{
const char *currentFile = archive_entry_pathname(entry);
char *fileContents;
entry_size = archive_entry_size(entry); //get the size of the file
fileContents = (char*)malloc(entry_size); //alloc enough for string - from my testing I see that this is how many bytes tar and ls report from command line
archive_read_data(a, fileContents, entry_size); //read data into fileContents string for the HTML file size
if(strcmp(currentFile, "vendar-definition.html") == 0)
{
printf("file name = %s, size = %ld\n", currentFile, entry_size);
printf("%s\n\n", fileContents); //this output over-reads chars from another file in this tar file
}
free(fileContents); //free the C string because I malloc'd
}
}
printf("exit");
}
下面是完整的列表或錯誤,我得到: d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager。 CPP:16:未定義參照_imp__archive_read_new' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:17: undefined reference to
小鬼 _archive_read_support_compression_none ' d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager.cpp:18:未定義參照_imp__archive_read_support_format_tar' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:19: undefined reference to
小鬼 _archive_read_open_filename' d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager.cpp:28:未定義參照_imp__archive_entry_pathname' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:30: undefined reference to
小鬼 _archive_entry_size」 d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager.cpp:32:未定義參照_imp__archive_read_data' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:26: undefined reference to
小鬼 _archive_read_next_header」 d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager.cpp:16:未定義參照_imp__archive_read_new' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:17: undefined reference to
小鬼 _archive_read_support_compression_none ' D:\ Tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar/TarFileManager.cpp:18:undefined參考_imp__archive_read_support_format_tar' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:19: undefined reference to
imp _archive_read_open_filename ' d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../焦油/ TarFileManager.cpp:28:未定義參照_imp__archive_entry_pathname' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:30: undefined reference to
小鬼 _archive_entry_size' d:\焦油集結桌面Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../Tar/TarFileManager.cpp:32:undefined參考_imp__archive_read_data' D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:26: undefined reference to
imp _archive_read_next_header'
你是否更新了庫路徑,並鏈接到庫?如果沒有發佈實際的錯誤,很難說出任何內容。 –