c++ - 使用 libdxf 的段错误

标签 c++ dxf

我正在尝试使用 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;
}

段错误的来源在上面的两行中,注释为//fault here

如何处理这个段错误?

最佳答案

我希望你在 Linux 上工作。

我编译了你的代码并通过替换成功运行

 #include<../src/dl_dxf.h>
 #include<../src/dl_creationadapter.h>

#include<dxflib/dl_dxf.h>
#include<dxflib/dl_creationadapter.h>

我在 Ubuntu 上通过包管理器安装了 libdxflib-dev 包(还有包含 libdxflib.so 的 libdxflib-2.5.0.0)。

它创建了一个空的“myfile.dxf”并退出。

由于您包含来自另一个目录的 dxf header ,我怀疑存在兼容性问题(可能在 dxf header 和共享对象文件之间)

如果您是 Ubuntu 用户,使用标准包编译程序可能有助于理解根本原因

 sudo apt-get install libdxflib-dev libdxflib-2.5.0.0

替换为

#include<dxflib/dl_dxf.h>
#include<dxflib/dl_creationadapter.h>

然后用命令编译

 g++ -Wall dxf.cpp -ldxflib -L/usr/lib/x86_64-linux-gnu/

然后运行a.out

请注意/usr/lib/x86_64-linux-gnu/是 libdxflib.so 所在的位置。在您的环境中可能有所不同。

关于c++ - 使用 libdxf 的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32167170/

相关文章:

c++ - 错误:静态断言失败:std::thread 参数在转换为右值后必须是可调用的

c++ - 运行使用 openCV 1.0 的应用程序时出现问题

C++ 命令行实用程序输入文件位置更改行为

svg 2 dxf 转换

c++ - 将输入文件存储到二维数组 C++

c++ - iOS 上的 OpenCv 2.4.9 background_segm.hpp #include <list> 未找到

c++ - 如何在我的程序中切换 Debug模式?

python - 使用python更改dxf文件中的图层名称

delphi - 从 Delphi 应用程序将文本样式写入 DXF

python - 使用 EZDXF Python 查找 DXF 文件的大小