首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Qt构建错误中使用libarchive

在Qt构建错误中使用libarchive
EN

Stack Overflow用户
提问于 2011-12-01 11:06:01
回答 1查看 1.8K关注 0票数 1

我已经掌握了藤黄,并在生成指令之后在生成指令和Linux上构建了示例。

现在我想在基于Qt的项目中使用这个库,所以我使用的是Qt创建者。我已经在我的pro文件中添加了libarchive的包含路径,但是当我编译时我会收到错误,上面写着“未定义的对‘imp_archive_read_new’的引用”等等。

这是我目前的代码:

代码语言:javascript
复制
    #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 toimp_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 toimp_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 toimp_archive_entry_size’D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar的未定义引用D:\Tar-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Tar/TarFileManager.cpp:16::对_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 toimp_archive_read_next_header的未定义引用:对_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 toimp_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 toimp_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 toimp_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 toimp_archive_read_next_header的未定义引用‘

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-01 11:46:57

正如我所怀疑的,这是一个连接问题。您实际上并没有链接到库。我不知道Qt是如何实现的,但是您必须将标志-L/path/to/library/folder-lname_of_library添加到链接阶段。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8340325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档