【问题标题】:Compiling libzip on Mac: Undefined symbols for architecture x86_64在 Mac 上编译 libzip:架构 x86_64 的未定义符号
【发布时间】:2016-01-15 20:32:13
【问题描述】:

我一直在学习 C++,并决定尝试在存档文件(例如 Word)上使用 libzip 创建一个简单的文件阅读器。

我最近使用 brew 在我的 Macbook 上安装了 libzip,但每当我尝试编译使用 libzip 的程序时,我似乎总是遇到以下问题:

Undefined symbols for architecture x86_64:
  "_zip_fopen", referenced from:
      _main in main-918bfa.o
  "_zip_open", referenced from:
      _main in main-918bfa.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [a.exe] Error 1

我用来编译的命令:

g++ -g main.cpp -std=c++11 -I/usr/local/Cellar/libzip/0.11.2/include -I/usr/local/Cellar/libzip/0.11.2/lib/libzip/include -L/usr/local/Cellar/libzip/0.11.2/lib -o ../a.exe

ma​​in.cpp:

 #include <iostream>
 #include <fstream>
 #include <zip.h>
 #include <zlib.h>

 using namespace std;
 int numArgs = 2;

 int main(int argc, char** argv){
     // Parse command line arguments
     if(argc != numArgs){
         std::cout << "Incorrect number of arguments provided.\n";
         std::cout << "Command line syntax: fileReader.exe inputFile" << endl;
         exit(0);
     }

     // Try out libzip functionality
     std::string inputDocument(argv[1]);
     int err = 0;
     zip* z = zip_open(inputDocument.c_str(), 0, &err);
     if(z == NULL) {
         printf("Could not read docx file. Error code: %d", err);
         exit(-1);
     }
     zip_file* contentTypes = zip_fopen(z, "[Content_Types].xml", ZIP_FL_UNCHANGED);
     exit(0);
 }

【问题讨论】:

    标签: c++ macos compiler-errors zip libzip


    【解决方案1】:

    看起来不像您在编译命令中包含 libzip 库。尝试将-lzip 添加到您的 g++ 命令中

    【讨论】:

    • 成功了,干杯!我猜这告诉编译器在编译程序时使用 libzip.a?
    • 是的,它告诉它寻找 libzip.a(用于静态编译)或 libzip.dylib(用于动态编译)
    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 2015-09-14
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 2013-02-07
    相关资源
    最近更新 更多