C ++ - PugiXML和SIGSEGV

时间:2015-02-13 12:05:52

标签: c++ xml c++11 pugixml

我需要在我的C ++程序中解析XML。所以我昨天决定使用PugiXML库。问题是,当我尝试使用此库中的任何内容时,我每次都会收到SIGSEGV错误。令人困惑的是,程序在getMessage()方法中中止,与PugiXML库没有任何共同之处。

你能看出问题在哪里吗?


CPP代码

#include <iostream>
#include <mpi.h>

#include "./lib/pugixml.hpp"
#include "./lib/pugiconfig.hpp"

using namespace std;
using namespace pugi;

class Message {

    private:
        string messageBody;

    public:
        Message( string messageBody ) {
            this->messageBody = messageBody;
        }

        bool isSpam() {
            return true;
        }
};

class Reader {

    public:
        virtual Message getMessage( string source ) = 0;

};

class FileMsgReader : public Reader {

    public:
        Message getMessage( string source ) {
            cout << "This method loads messages from file " << source << endl;

            Message m("mm");
            return m;
        }
};

class WebMsgReader : public Reader {

    public:
        Message getMessage( string source ) {
            cout << "This method loads messages from webpage" << endl;

            Message m("mm");
            return m;
        }
};

int main() {
    FileMsgReader fmr;
    WebMsgReader wmr;

    fmr.getMessage("file.txt");
    wmr.getMessage( "www.google.com" );

    cout << "Hello" << endl;

    //-----------------------//
    //--- MESSAGE PASSING ---//
    //-----------------------//
    MPI_Init( NULL, NULL );

    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    cout << "process rank: " << world_rank << endl;

    xml_document doc; // here is the problem

    MPI_Finalize();
    return 0;
}

生成文件

CC=mpic++
STD=-std=c++11
BINARIES=start
OBJECT_FILES=*.o

.DEFAULT_TARGET: start
.PHONY: clean libraries

start: main.o libraries
    ${CC} main.o -o start ${STD} -L./lib -lpugixml

main.o: main.cpp
    ${CC} main.cpp -c -o main.o ${STD}

libraries:
    $(MAKE) -C lib

clean:
    rm -f ${BINARIES} ${OBJECT_FILES} nohup.out
    $(MAKE) clean -C lib

项目目录结构

spam_detector
├── lib
│   ├── makefile
│   ├── pugiconfig.hpp
│   ├── pugixml.cpp
│   └── pugixml.hpp
├── main.cpp
├── makefile
├── pokus.cpp
└── test.xml

0 个答案:

没有答案