yaml-cpp



  • Moin,

    ich bin noch recht neu in der Programmierung von C++ unter Linux und komme da grad nicht weiter.

    Wenn ich folgenden Source versuche zu kompilieren

    #include <cstdlib>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <mysql/mysql.h>
    #include <yaml-cpp/yaml.h>
    #include <fstream>
    
    using namespace std;
    
    int main(int argc, char** argv) {
    
        int c;
        char *configfile = NULL;
    
        int index;
        int intStat;
        struct stat stFileInfo;
    
        while ((c = getopt (argc, argv, "c:")) != -1)
        {
            switch (c)
    	{
                case 'c':
                    configfile = optarg;
    		break;
                default:
                    abort();
            }
        }
    
        printf ("Config File: %s\n", configfile);
    
        for (index = optind; index < argc; index++) {
            printf ("Non-option argument %s\n", argv[index]);
        }
    
        intStat = stat(configfile,&stFileInfo);
        if(intStat == 0) {
    
            try {
                std::ifstream fin(configfile);
                YAML::Parser parser(fin);
    
                YAML::Node doc;
                while(parser.GetNextDocument(doc)) {
                   // ...
                }
            } catch(YAML::ParserException& e) {
                std::cout << e.what() << "\n";
            }
    
        } else {
            printf ("Config file '%s' does not exit", configfile);
        }
    
        return 0;
    }
    

    gibt mir Netbeans diese Fehler:

    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    rm -f -r build/Debug
    rm -f dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'

    CLEAN SUCCESSFUL (total time: 74ms)
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[2]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    mkdir -p build/Debug/GNU-Linux-x86
    rm -f build/Debug/GNU-Linux-x86/main.o.d
    g++ -c -g -I/usr/local/include -I/usr/include -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
    mkdir -p dist/Debug/GNU-Linux-x86
    g++ -o dist/Debug/GNU-Linux-x86/wordlistfromdb build/Debug/GNU-Linux-x86/main.o
    build/Debug/GNU-Linux-x86/main.o: In function main': /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:44: undefined reference toYAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:46: undefined reference to YAML::Node::Node()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:47: undefined reference toYAML::Parser::GetNextDocument(YAML::Node&)'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference to YAML::Node::~Node()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference toYAML::Node::~Node()'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference to YAML::Parser::~Parser()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference toYAML::Parser::~Parser()'
    collect2: ld returned 1 exit status
    make[2]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    make[2]: *** [dist/Debug/GNU-Linux-x86/wordlistfromdb] Fehler 1
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    make[1]: *** [.build-conf] Fehler 2
    make: *** [.build-impl] Fehler 2

    BUILD FAILED (exit value 2, total time: 584ms)

    Was läuft falsch?

    Grüße,
    eins11



  • Ganz wichtig: Compiler/Linker Fehlermeldungen verstehen.

    Hier hast du vergessen, die YAML Libs mit einzubinden.



  • Wenn ich "/usr/local/lib" als Library Pfad hinzufüge in denen sich die libyaml-Dateien befinden

    /usr/local/lib/libyaml-cpp.so.0.2.5
    /usr/local/lib/libyaml-cpp.so.0.2
    /usr/local/lib/libyaml-cpp.so

    ändert sich aber auch nicht viel:

    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    rm -f -r build/Debug
    rm -f dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'

    CLEAN SUCCESSFUL (total time: 90ms)
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[2]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    mkdir -p build/Debug/GNU-Linux-x86
    rm -f build/Debug/GNU-Linux-x86/main.o.d
    g++ -c -g -I/usr/local/include -I/usr/include -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
    mkdir -p dist/Debug/GNU-Linux-x86
    g++ -o dist/Debug/GNU-Linux-x86/wordlistfromdb build/Debug/GNU-Linux-x86/main.o -L/usr/local/lib
    make[2]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    build/Debug/GNU-Linux-x86/main.o: In function main': /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:44: undefined reference toYAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:46: undefined reference to YAML::Node::Node()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:47: undefined reference toYAML::Parser::GetNextDocument(YAML::Node&)'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference to YAML::Node::~Node()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference toYAML::Node::~Node()'
    /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference to YAML::Parser::~Parser()' /home/eins11/projekte/cpp/WordlistFromDB/main.cpp:49: undefined reference toYAML::Parser::~Parser()'
    collect2: ld returned 1 exit status
    make[2]: *** [dist/Debug/GNU-Linux-x86/wordlistfromdb] Fehler 1
    make[1]: *** [.build-conf] Fehler 2
    make: *** [.build-impl] Fehler 2

    BUILD FAILED (exit value 2, total time: 676ms)



  • Du musst noch die Lib direkt angeben: -L für Lib-Pfad, -l für die Lib

    Also der gcc-Aufruf muss soetwas enthalten: gcc [..] -LYamlLibPath -lyaml-cpp.so [..]

    Denk mal, das ist bei den Shared Objects genauso wie bei den Object Archives.



  • Ah, jetzt hab ichs 😉 Wenn auch irgendwie anders, glaub ich 😉

    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    rm -f -r build/Debug
    rm -f dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'

    CLEAN SUCCESSFUL (total time: 99ms)
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
    make[1]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/wordlistfromdb
    make[2]: Betrete Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    mkdir -p build/Debug/GNU-Linux-x86
    rm -f build/Debug/GNU-Linux-x86/main.o.d
    g++ -c -g -I/usr/local/include -I/usr/include -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
    mkdir -p dist/Debug/GNU-Linux-x86
    g++ -o dist/Debug/GNU-Linux-x86/wordlistfromdb build/Debug/GNU-Linux-x86/main.o /usr/local/lib/libyaml-cpp.so
    make[2]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'
    make[1]: Verlasse Verzeichnis '/home/eins11/projekte/cpp/WordlistFromDB'

    BUILD SUCCESSFUL (total time: 1s)



  • Nur eine andere Syntax 😉

    Ob "gcc -L<path> -l<name>" oder "gcc [..] <path>/lib<libname>" ist egal. Siehe gcc-Reference...


Anmelden zum Antworten