linker - Error: C++ unresolved external symbol -
this question has answer here:
i using 2 c files written others in c++ project in visual studio 2008 (actually, provided free online polygon intersection library).
the 2 files downloaded gcp.h , gcp.c. copied gcp.h , gcp.c project directory. linker gave me error:
unresolved external symbol: void __cdecl gpc_polygon_clip(enum gpc_op,struct gpc_polygon *,struct gpc_polygon *,struct gpc_polygon *)
below how wrote code uses library:
static int poly_intersection(convex_polygon& poly1,convex_polygon& poly2,convex_polygon& rp) { if(!poly1.is_convex() || !poly2.is_convex()) return 1; // construct 1st convex polygon gpc_vertex *gvp1 = new gpc_vertex[poly1.size()]; gpc_vertex v1; (unsigned int n = 0; n < poly1.size(); n++) { v1.x = poly1.vertex(n).x(); v1.y = poly1.vertex(n).y(); gvp1[n] = v1; } gpc_vertex_list gvl1; gvl1.num_vertices = poly1.size(); gvl1.vertex = gvp1; gpc_vertex_list *gvlp1 = new gpc_vertex_list[1]; gvlp1[0] = gvl1; gpc_polygon gp1; gp1.num_contours = 1; gp1.hole = 0; gp1.contour = gvlp1; // construct 2st convex polygon gpc_vertex *gvp2 = new gpc_vertex[poly2.size()]; gpc_vertex v2; (unsigned int n = 0; n < poly2.size(); n++) { v2.x = poly2.vertex(n).x(); v2.y = poly2.vertex(n).y(); gvp2[n] = v2; } gpc_vertex_list gvl2; gvl2.num_vertices = poly2.size(); gvl2.vertex = gvp2; gpc_vertex_list *gvlp2 = new gpc_vertex_list[1]; gvlp2[0] = gvl2; gpc_polygon gp2; gp2.num_contours = 1; gp2.hole = 0; gp2.contour = gvlp2; // convex polygon intersection gpc_polygon result; gpc_polygon_clip(gpc_int, &gp1, &gp2, &result);
and clarity, content of 2 files used are
#gcp.h #define gpc_epsilon (dbl_epsilon) #define gpc_version "2.32" /* =========================================================================== public data types =========================================================================== */ typedef enum /* set operation type */ { gpc_diff, /* difference */ gpc_int, /* intersection */ gpc_xor, /* exclusive or */ gpc_union /* union */ } gpc_op; typedef struct /* polygon vertex structure */ { double x; /* vertex x component */ double y; /* vertex y component */ } gpc_vertex; typedef struct /* vertex list structure */ { int num_vertices; /* number of vertices in list */ gpc_vertex *vertex; /* vertex array pointer */ } gpc_vertex_list; typedef struct /* polygon set structure */ { int num_contours; /* number of contours in polygon */ int *hole; /* hole / external contour flags */ gpc_vertex_list *contour; /* contour array pointer */ } gpc_polygon; typedef struct /* tristrip set structure */ { int num_strips; /* number of tristrips */ gpc_vertex_list *strip; /* tristrip array pointer */ } gpc_tristrip; /* =========================================================================== public function prototypes =========================================================================== */ void gpc_read_polygon (file *infile_ptr, int read_hole_flags, gpc_polygon *polygon); void gpc_write_polygon (file *outfile_ptr, int write_hole_flags, gpc_polygon *polygon); void gpc_add_contour (gpc_polygon *polygon, gpc_vertex_list *contour, int hole); void gpc_polygon_clip (gpc_op set_operation, gpc_polygon *subject_polygon, gpc_polygon *clip_polygon, gpc_polygon *result_polygon); void gpc_tristrip_clip (gpc_op set_operation, gpc_polygon *subject_polygon, gpc_polygon *clip_polygon, gpc_tristrip *result_tristrip); void gpc_polygon_to_tristrip (gpc_polygon *polygon, gpc_tristrip *tristrip); void gpc_free_polygon (gpc_polygon *polygon); void gpc_free_tristrip (gpc_tristrip *tristrip); #endif
before own method @ beginning of c++ header file, put #include "gpc.h", thought take care of it. didn't work.
if use c function in .cpp file, include c header file below:
extern "c" { #include "gpc.h" }
because function symbol in c , c++ different.
Comments
Post a Comment