I'm writing a C++ program in Visual Studio 2017 that is trying to make use of this C program: https://www.cs.cmu.edu/~quake/triangle.html
I have extern "C" {#include triangle.h} at the beginning of my program but I'm still getting an error:
LNK2019 unresolved external symbol _triangulate referenced in function "void __cdecl createTriangulation(void)" (?createTriangulation@@YAXXZ) GLTests C:\Users\Connor McDermott\source\repos\GLTests\GLTests\main.obj 1
Here's the function where I call triangulate from:
void createTriangulation() {
triangulateio in, out;
/* Define input points. */
in.numberofpoints = pts.size();
in.numberofpointattributes = 0;
in.pointlist = (REAL *)malloc(in.numberofpoints * 2 * sizeof(REAL));
for (int i = 0; i < pts.size(); i++) {
in.pointlist[2 * i] = pts[i].x;
in.pointlist[2 * i + 1] = pts[i].y;
}
in.pointmarkerlist = (int *)NULL;
in.numberofsegments = pts.size();
in.segmentlist = (int *)malloc(in.numberofsegments * 2 * sizeof(int));
in.segmentlist[0] = pts.size() - 1;
in.segmentlist[1] = 0;
for (int i = 1; i < pts.size(); i++) {
in.segmentlist[2 * i] = i - 1;
in.segmentlist[2 * i + 1] = i;
}
in.numberofholes = 0;
in.numberofregions = 0;
out.pointlist = (REAL *)NULL; /* Not needed if -N switch used. */
/* Not needed if -N switch used or number of point attributes is zero: */
out.pointattributelist = (REAL *)NULL;
out.pointmarkerlist = (int *)NULL; /* Not needed if -N or -B switch used. */
out.trianglelist = (int *)NULL; /* Not needed if -E switch used. */
/* Not needed if -E switch used or number of triangle attributes is zero: */
out.triangleattributelist = (REAL *)NULL;
out.neighborlist = (int *)NULL; /* Needed only if -n switch used. */
/* Needed only if segments are output (-p or -c) and -P not used: */
out.segmentlist = (int *)NULL;
/* Needed only if segments are output (-p or -c) and -P and -B not used: */
out.segmentmarkerlist = (int *)NULL;
out.edgelist = (int *)NULL; /* Needed only if -e switch used. */
out.edgemarkerlist = (int *)NULL; /* Needed if -e used and -B not used. */
char switches[6] = { 'p', 'z', 'B', 'P', 'N' };
triangulate(switches, &in, &out, (struct triangulateio *) NULL);
for (int i = 0; i < out.numberofsegments; i++) {
edge e;
e.p0 = pts[out.segmentlist[2 * i]];
e.p1 = pts[out.segmentlist[2 * i + 1]];
}
}
I've tried looking at the questions about this error, but there's so many possible causes that I can't find which one applies to this situation. The most common problem seems to be not using extern "C" when including the header of a c program, but I've done that.
So what am I doing wrong?
Thanks to anyone who can help.