libconfig体系结构x86_64的未定义符号

时间:2016-10-20 21:43:23

标签: c++ libconfig

我正在尝试用c ++中的libconfig运行我的第一个基本程序。我用g++ testing.cpp -o testing编译。

#include <iostream>
#include <cstdlib>
#include <libconfig.h++>

using namespace std;
using namespace libconfig;

int main(){

    Config cfg;

    // Read the file. If there is an error, report it and exit.
    //try
    //{
    cfg.readFile("/tmp/eg-report-hutapp02q-161017-08-26/eg.cfg");
    //}
    /*catch(const FileIOException &fioex)
    {
            cerr << "I/O error while reading file." << endl;
            return(EXIT_FAILURE);
    }
    catch(const ParseException &pex)
    {
            cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
                      << " - " << pex.getError() << std::endl;
            return(EXIT_FAILURE);
    }*/

    cout << "This compiled" << endl;

    return 0;
}

当我在rhel6上运行时,我收到以下错误(仅第一行):

testing.cpp:(.text+0x13): undefined reference to ``libconfig::Config::Config()'

当我在Mac Darwin Kernel 15.5.0上运行时,我收到此错误:

Undefined symbols for architecture x86_64: "libconfig::Config::readFile(char const*)", referenced from: _main in testing-59bdf7.o "libconfig::Config::Config()", referenced from: _main in testing-59bdf7.o "libconfig::Config::~Config()", referenced from: _main in testing-59bdf7.o "typeinfo for libconfig::ParseException", referenced from: GCC_except_table0 in testing-59bdf7.o "typeinfo for libconfig::FileIOException", referenced from: GCC_except_table0 in testing-59bdf7.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

这只是下载的libconfig-1.5.tar.gz文件的一个示例。我在mac上经历了makefile进程,得到了那个错误,然后brew安装了libconfig-1.6并仍然收到了同样的错误。我在这里不知所措。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您需要将库链接到可执行文件。

documentation中所述,将-lconfig++添加到编译器标志中,它应该可以正常工作。

基本上,这告诉编译器在哪里可以找到库源(类,函数等),以便在需要时可以在程序中正确导入它们。

相关问题