2016-10-20 1 views
0

J'essaie d'exécuter mon premier programme de base avec libconfig en C++. J'ai compilé avec g++ testing.cpp -o testing.libconfig Symboles non définis pour l'architecture x86_64

#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; 
} 

Quand je cours sur RHEL6, je reçois l'erreur suivante (seule la première ligne):

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

Quand je lance sur Mac Darwin noyau 15.5.0, je reçois cette erreur:

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)

Ceci est juste un exemple de fichier libconfig-1.5.tar.gz téléchargé. Je suis passé par le processus makefile sur le mac, j'ai eu cette erreur, puis j'ai installé libconfig-1.6 et j'ai quand même reçu la même erreur. Je suis à perte ici. Toute aide est appréciée.

+0

Pouvez-vous ajouter la commande du compilateur que vous utilisez? Quels drapeaux utilisez-vous? – ShadowMitia

+0

@ShadowMitia J'ai ajouté la commande au début. Je viens d'utiliser un simple 'g ++ testing.cpp -o testing'. Donc, pas de drapeaux spéciaux. – TriHard8

Répondre

0

Vous devez lier la bibliothèque à votre exécutable.

Comme indiqué dans le documentation ajouter -lconfig++ à vos indicateurs de compilation et cela devrait fonctionner. Fondamentalement, cela indique au compilateur où trouver les sources de la bibliothèque (classes, fonctions, etc) afin qu'ils puissent être importés correctement dans votre programme en cas de besoin.