我正在尝试使用libdxf
库。我创建了一个正在运行的小程序,但我遇到了分段错误。我已经使用调试我的代码gdb
并找到了导致核心被转储的代码行。
我的代码片段如下所示:
#include<iostream>
#include<../src/dl_dxf.h>
#include<../src/dl_creationadapter.h>
using namespace std;
class Test:public DL_CreationAdapter {
public:
void write();
};
void Test::write(){
DL_Dxf *dxf = new DL_Dxf(); // fault here
DL_Codes::version exportVersion = DL_Codes::AC1015;
DL_WriterA* dw = dxf->out("myfile.dxf", exportVersion);
if (dw==NULL) {
printf("Cannot open file 'myfile.dxf' \
for writing.");
}
delete dxf;
}
int main(){
Test test;
test.write(); // fault here
return 0;
}
分段错误的来源在上面的 2 行中,带有注释//fault here
。
如何处理这种分段错误?