在Qt中使用libarchive - 构建错误

时间:2011-12-01 11:06:02

标签: c++ qt archive tar

我抓住了libarchive并在build instructions之后在Windows和Linux上构建了示例。

我现在想在我的项目中使用这个库,这是基于Qt的,所以我正在使用Qt创建者。我在我的专业文件中添加了libarchive的包含路径,但是当我编译时,我得到的错误是“未定义引用' 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:\ tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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 imp _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:对_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:\ Tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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 imp _archive_entry_size'的未定义引用 D:\ tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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 imp _archive_read_next_header'的未定义引用 D:\ tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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 imp _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:对_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:\ Tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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 imp _archive_entry_size'的未定义引用 D:\ Tar-build-desktop-Qt_4_7_4_for_Desktop _-_ MinGW_4_4__Qt_SDK__Debug /../ Tar / 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的未定义引用 imp _archive_read_next_header'

1 个答案:

答案 0 :(得分:1)

我怀疑,这是一个链接问题。您实际上并未链接到库。我不知道你是如何在Qt Creator中做到的,但是你必须将标志-L/path/to/library/folder-lname_of_library添加到链接阶段。