0
votes

I'm trying to run my first basic program with libconfig in c++. I compiled with 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;
}

When I run on rhel6, I get the following error (only the first line):

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

When I run on Mac Darwin Kernel 15.5.0, I get this error:

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)

This is just an example from downloaded libconfig-1.5.tar.gz file. I went through the makefile process on the mac, got that error, then brew installed libconfig-1.6 and still received the same error. I'm at a loss here. Any help is appreciated.

1
Can you add the compiler command you're using? What flags are you using?ShadowMitia
@ShadowMitia I added the command to the beginning. I just used a simple g++ testing.cpp -o testing. So no special flags.TriHard8

1 Answers

0
votes

You need to link the library to your executable.

As stated in the documentation add -lconfig++ to your compiler flags and it should work.

Basicly this tells the compiler where to find the library sources (classes, functions, etc) so that they can be properly imported in your program when needed.