is there rule i'm unaware of regarding how c header-only file, contains actual implementations, gets linked c++?
i have header-only c file includes full definitions of several functions. when include file in .cpp
file, , compile, linker reports several of functions named in file undefined.
the error looks this:
undefined symbols architecture i386: "par_shapes_free_mesh(par_shapes_mesh_s*)", referenced from: app::testgeo() in app.o
the c file has in it:
void par_shapes_free_mesh(par_shapes_mesh*); //forward declaration void par_shapes_free_mesh(par_shapes_mesh* mesh) { free(mesh->points); free(mesh->triangles); free(mesh->normals); free(mesh->tcoords); free(mesh); }
clearly, function in fact defined. include file @ top of app.cpp , use par_shapes_free_mesh
produces error. i'm confounded.
i tried following trick made no difference:
#ifdef __cplusplus extern "c" { #endif //and corresponding end brace
this had interesting effect of providing same error messages, underscore in name:
"_par_shapes_free_mesh", referenced from:
there typedef in file:
typedef struct par_shapes_mesh_s { float* points; int npoints; uint16_t* triangles; int ntriangles; float* normals; float* tcoords; } par_shapes_mesh;
in order definitions included during compilation need add #define par_shapes_implementation
source file before including par_shapes.h
.
#define par_shapes_implementation #include "par_shapes.h"
Comments
Post a Comment