linking to libredwg in c++ not working -


i'm trying use libredwg open , understand dwg files. have installed , @ least got of test programs run (even if seg fault later on). anyway, have included small header file in project similar simple example found here https://github.com/h4ck3rm1k3/libredwg/blob/master/examples/load_dwg.c there seems general problem data types (at least in way i'm compiling it) meaning i've added few casts of form (char*) number of variables trying automatically convert (void*) , (unsigned char*) type (char*) , got rid of compiler complaints. still when compile so

g++ xxx.c++ -l/opt/local/lib/ -lredwg -o program_name 

i following error:

undefined symbols 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 architecture x86_64 collect2: ld returned 1 exit status 

i'm not sure do, i've fixed problems in source compiler complains , linking relevant libraries -lredwg (right? haven't missed any?). header file test functionality , looks like:

#include "suffix.c" #include <dwg.h>  plan floor_plan;//temporary data structure defined elsewhere   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 }  void add_text(double x, double y, char *txt) {     // make }  int load_dwg(char *filename) {     unsigned int i;     int success;     dwg_data dwg;      dwg.num_objects = 0;     success = dwg_read_file(filename, &dwg);     (i = 0; < 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; } 

what doing wrong? believe libredwg written in c. problem?

it seems trying link against 32 bit library when you're on 64 bit platform, in answer. solution download (or build source) 64 bit version of libredwg. or alternatively add "-m32" flag g++ command line - build whole app 32 bit executable.

edit : have found out, problem caused trying link c++ code c library without following @ top / bottom of code :

#ifdef __cplusplus  extern "c" {  #endif 

// ... source code here

#ifdef __cplusplus }  #endif  

basically tells compiler not c++ name-mangling - switching name mangling off allows linking between c , c++


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -