我需要在我的 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