我正在尝试使用 libreDWG 打开和理解一些 dwg 文件。我已经安装了它,并且至少可以运行一些测试程序(即使它们稍后会出现故障)。无论如何,我在我的项目中包含了一个小头文件,与此处找到的简单示例非常相似https://github.com/h4ck3rm1k3/libredwg/blob/master/examples/load_dwg.c数据似乎存在一般问题类型(至少在我编译它的方式上)意味着我已经添加了一些表单类型 (char*) 到以前试图自动转换 (void*) 和 (unsigned char*) 到类型 ( char*) 并摆脱了那些编译器的抱怨。但即使当我像这样编译它时
g++ xxx.c++ -L/opt/local/lib/ -lredwg -o program_name
我收到以下错误:
Undefined symbols for architecture x86_64:
"dwg_read_file(char*, _dwg_struct*)", referenced from:
load_dwg(char*)in ccN6HUqz.o
"dwg_free(_dwg_struct*)", referenced from:
load_dwg(char*)in ccN6HUqz.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我不知道该怎么做,我已经修复了编译器抱怨的源代码中的任何问题,并且正在使用 -lredwg 链接到相关库(对吗?我没有错过任何问题?)。我的头文件只是为了测试功能,看起来像:
#include "suffix.c"
#include <dwg.h>
plan floor_plan;//temporary data structure defined elsewhere for now
void
add_line(double x1, double y1, double x2, double y2)
{
line_in temp;
temp.start.x=x1;
temp.start.y=y1;
temp.end.x=x2;
temp.end.y=y2;
floor_plan.lines.push_back(temp);
std::cout<<"LINE: :"<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<std::endl;
}
void
add_circle(double x, double y, double R)
{
// Yet to do
}
void
add_text(double x, double y, char *txt)
{
// Make something with that
}
int
load_dwg(char *filename)
{
unsigned int i;
int success;
Dwg_Data dwg;
dwg.num_objects = 0;
success = dwg_read_file(filename, &dwg);
for (i = 0; i < dwg.num_objects; i++)
{
Dwg_Entity_LINE *line;
Dwg_Entity_CIRCLE *circle;
Dwg_Entity_TEXT *text;
switch (dwg.object[i].type)
{
case DWG_TYPE_LINE:
line = dwg.object[i].tio.entity->tio.LINE;
add_line(line->start.x, line->end.x, line->start.y, line->end.y);
break;
case DWG_TYPE_CIRCLE:
circle = dwg.object[i].tio.entity->tio.CIRCLE;
add_circle(circle->center.x, circle->center.y, circle->radius);
break;
case DWG_TYPE_TEXT:
text = dwg.object[i].tio.entity->tio.TEXT;
add_text(text->insertion_pt.x, text->insertion_pt.y, (char*) text->text_value);
break;
}
}
dwg_free(&dwg);
return success;
}
我究竟做错了什么?我相信 libredwg 是用 c 编写的。这是问题吗?