我试图使用libreDWG打开和理解一些dwg文件。我已经安装了它,并且至少有一些测试程序要运行(即使它们稍后会出现故障)。无论如何,我在我的项目中包含了一个小的头文件,非常类似于在这里发现的简单示例,dwg.c数据类型似乎有一个普遍的问题(至少在我编译它的方式中),这意味着我已经添加了一些表单(char*)到变量数的转换,这些变量以前试图自动地将(void*)和(unsigned *)转换成类型(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.写的,这是问题吗?
发布于 2014-03-24 14:26:19
在64位平台上时,您似乎试图链接到32位库,就像在这个answer中一样。解决方案是下载(或者从源代码中构建自己)一个64位版本的libredwg。或者将"-m32“标志添加到g++命令行--将整个应用程序构建为32位可执行文件。
编辑:正如您已经发现的,这个问题实际上是由于试图将C++代码与C库链接而导致的,而代码的顶部/底部没有如下内容:
#ifdef __cplusplus
extern "C" {
#endif// .这里的源代码
#ifdef __cplusplus
}
#endif 这基本上告诉编译器not to do C++ name-mangling切换名称删除允许C和C++之间的链接。
https://stackoverflow.com/questions/22611907
复制相似问题