Неразрешенная внешняя ошибка при использовании функции C в Visual Studio 2017 - PullRequest
0 голосов
/ 01 мая 2018

Я пишу программу на C ++ в Visual Studio 2017, которая пытается использовать эту программу на C: https://www.cs.cmu.edu/~quake/triangle.html

У меня есть extern "C" {#include triangle.h} в начале моей программы, но я все еще получаю ошибку:

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   

Вот функция, из которой я вызываю триангуляцию:

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]];
}

}

Я пытался посмотреть на вопросы об этой ошибке, но есть так много возможных причин, которые я не могу найти, какая из них относится к этой ситуации. Наиболее распространенная проблема, по-видимому, заключается в том, что при включении заголовка программы c не используется extern «C», но я это сделал.

Так что я делаю не так?

Спасибо всем, кто может помочь.

...