我已经下载并安装了 jsoncpp 库。然后我尝试在我自己的应用程序中使用该库:
#include <json/json.h>
void parseJson() {
Json::Reader reader;
}
int main(int argc, char ** argv) {
parseJson();
exit(0);
}
该程序可以正常编译和链接,但在运行时会因 SIGSEGV 崩溃。gdb 回溯如下所示:
(gdb) bt
#0 0x0000003a560b7672 in __gnu_cxx::__exchange_and_add () from /usr/lib64/libstdc++.so.6
#1 0x00000000004031e9 in std::string::_Rep::_M_dispose (this=0xffffffffffffffe9, __a=@0x7fffbfe60e57)
at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:232
#2 0x0000000000403236 in ~basic_string (this=0x7fffbfe60fb0)
at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:478
#3 0x00000000004038d4 in ~Reader (this=0x7fffbfe60eb0) at /private/joaho/Parser/opm-parser/external/json/json-cpp/include/json/reader.h:23
#4 0x0000000000402990 in parseJson () at /private/joaho/Parser/opm-parser/opm/parser/eclipse/ExternalTests/ExternalTests.cpp:51
#5 0x00000000004029ab in main (argc=1, argv=0x7fffbfe610c8)
at /home/user/Parser/opm-parser/opm/parser/eclipse/ExternalTests/ExternalTests.cpp:56
即对我来说,它似乎在析构函数中崩溃了。据我所知, Json::Reader 没有自己的析构函数,所以这必须是默认析构函数。如您所见,我正在运行一个相当旧版本的 g++ - 这可能是问题吗?