I am trying to use libdxf
library. I have created a small program running which I am getting a segmentation fault. I have debugged my code using gdb
and have located the code line causing the core to be dumped.
My code snippet is as written below:
#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;
}
The source of segmentation fault is in 2 lines above with the comment //fault here
.
How to handle this segmentation fault?
I wish you are working on Linux.
I compiled your code an ran succesfully just by replacing
#include<../src/dl_dxf.h>
#include<../src/dl_creationadapter.h>
with
#include<dxflib/dl_dxf.h>
#include<dxflib/dl_creationadapter.h>
I installed libdxflib-dev package via package manager on Ubuntu(And also libdxflib-2.5.0.0 that includes the libdxflib.so).
It created an empty 'myfile.dxf' and exited.
Since you include dxf headers from another directory I suspect that there is a compatibility problem (possibly between dxf headers and the shared object file)
If you are an Ubuntu user below lines to compile the program via using standart packages may be helpful to understand the root cause
sudo apt-get install libdxflib-dev libdxflib-2.5.0.0
replace inclusions with
#include<dxflib/dl_dxf.h>
#include<dxflib/dl_creationadapter.h>
then compile with command
g++ -Wall dxf.cpp -ldxflib -L/usr/lib/x86_64-linux-gnu/
and run a.out
Note that /usr/lib/x86_64-linux-gnu/ is where libdxflib.so stands. It may be different in your environment.