Unresolved External symbol, C++, VS 2015 [duplicate]

不想你离开。 提交于 2019-12-25 07:04:51

问题


I have read the model answer on unresolved externals and found it to be incredibly useful and have got it down to just these last two stubborn errors which are beyond me.

I've attached all the code just in case, if you would like to see the headers or anything else please say.

// Stokes theory calculations

#include <math.h>
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#define ANSI
#include "../Allocation.h"

#define Main
#define Char    char
#define Int     int
#define Double  double
#include "../Allocation.h"
#include "../Headers.h"


Double
kH, skd, ckd, tkd, SU;
Double
ss[6], t[6], C[6], D[6], E[6], e[6];

// Main program

int main(void)
{
    int i, Read_data(void), iter, Iter_limit = 40;

    double  F(double), kd1, kd2, kFM, omega, delta, accuracy = 1.e-6, F1, F2, Fd;
    void    CDE(double), AB(void), Output(void);

    Input1 = fopen("../Data.dat", "r");
    strcpy(Convergence_file, "../Convergence.dat");
    strcpy(Points_file, "../Points.dat");
    monitor = stdout;
    strcpy(Theory, "Stokes");
    strcpy(Diagname, "../Catalogue.res");

    Read_data();

    z = dvector(0, 2 * n + 10);
    Y = dvector(0, n);
    B = dvector(0, n);
    coeff = dvector(0, n);
    Tanh = dvector(0, n);

    monitor = stdout;

    H = MaxH;

    iff(Case, Wavelength)
    {
        kd = 2. * pi / L;
        kH = kd * H;
        CDE(kd);
    }

    // If period is specified, solve dispersion relation using secant method

    // Until February 2015 the bisection method was used for this.
    // I found that in an extreme case (large current) the bracketting
    // of the solution was not correct, and the program failed,
    // without printing out a proper error message.

    iff(Case, Period)
    {
        fprintf(monitor, "\n# Period has been specified.\n# Now solving for L/d         iteratively, printing to check convergence\n\n");
        omega = 2 * pi / T;
        // Fenton & McKee for initial estimate
        kFM = omega*omega*pow(1 / tanh(pow(omega, 1.5)), (2. / 3.));
        kd1 = kFM;
        kd2 = kFM*1.01;
        CDE(kd2);
        F2 = F(kd2);
        for (iter = 1; iter <= Iter_limit; ++iter)
        {
            CDE(kd1);
            F1 = F(kd1);
            Fd = (F2 - F1) / (kd2 - kd1);
            delta = F1 / Fd;
            kd2 = kd1;
            kd1 = kd1 - delta;
            fprintf(monitor, "%8.4f\n", 2 * pi / kd1);
            if (fabs(delta / kd1) < accuracy) break;
            F2 = F1;
            if (iter >= Iter_limit)
            {
                printf("\n\nSecant for solution of wavenumber has not converged");
                printf("\nContact John Fenton johndfenton@gmail.com");
                getch();
                exit(1);
            }
        }
        kd = kd1;
        kH = kd * H;
    }

    z[1] = kd;
    z[2] = kH;

    SU = 0.5*kH / pow(kd, 3);
    printf("\n# Stokes-Ursell no.: %7.3f", SU);
    if (SU > 0.5)
        printf(" > 1/2. Results are unreliable");
    else
        printf(" < 1/2, Stokes theory should be valid");

    e[1] = 0.5 * kH;
    for (i = 2; i <= n; i++) e[i] = e[i - 1] * e[1];

    // Calculate coefficients

    AB();

    z[7] = C[0] + e[2] * C[2] + e[4] * C[4]; // ubar
    z[8] = -e[2] * D[2] - e[4] * D[4];
    z[9] = 0.5 * C[0] * C[0] + e[2] * E[2] + e[4] * E[4];

    if (Current_criterion == 1)
    {
        z[5] = Current*sqrt(kd);
        z[4] = z[7] + z[5];
        z[6] = z[4] + z[8] / kd - z[7];
    }

    if (Current_criterion == 2)
    {
        z[6] = Current*sqrt(kd);
        z[4] = z[6] - z[8] / kd + z[7];
        z[5] = z[4] - z[7];
    }

    iff(Case, Wavelength) z[3] = 2 * pi / z[4];
    iff(Case, Period) z[3] = T * sqrt(kd);

    for (i = 1; i <= n; i++)
        Tanh[i] = tanh(i*z[1]);

    //  Output results and picture of wave

    Solution = fopen("Solution.res", "w");
    Elevation = fopen("Surface.res", "w");
    Flowfield = fopen("Flowfield.res", "w");

    Output();

    fflush(NULL);
    printf("\nTouch key to continue "); getch();
    printf("\n\nFinished\n");
}

I get these error messages:

LNK2019 unresolved external symbol "void __cdecl Output(void)" (?Output@@YAXXZ) referenced in function _main Stokes

LNK2019 unresolved external symbol "double * __cdecl dvector(long,long)" (?dvector@@YAPANJJ@Z) referenced in function _main Stokes

I have checked everything on the list given to try and find where these errors are coming from and have whittled it down to just these two left.

Things tried so far:

  1. Checking basic syntax
  2. Checking and ensuring correct headers are available
  3. Looked at external dependencies (but i don't really know what i'm doing here)
  4. Looked at the solutions tried here but none worked.

Any help would be greatly appreciated!


回答1:


Unresolved External Symbols means that your code can't find the definition of the method or class you're trying to use. This usually means one (or more) of several things has happened:

  1. You didn't point to the directory that contains the object library (.lib on Windows, .so on Linux) for the library you're using
  2. You forgot to specify in the linker that you need to use the library in question (that list of kernel32.lib, user32.lib,... needs to include the name of the library you're using)
  3. The library you're trying to use is meant to be linked statically and you're trying to link it dynamically (or vise-versa). Check the documentation for the library and make sure you're using the correct form. Some libraries expect extra #define statements to be included or omitted depending on whether you're linking statically or dynamically.
  4. You changed build options and forgot to update the libraries in the other build options. If you're set to Release or x64, check to make sure that your build options are set correctly in all environments.

EDIT: I'll also corroborate what the others said in the original comment thread: make sure that the code that defines Output() and dvector() are being linked to by your code.

There's a few other options, but those are the big ones that happen most frequently.



来源:https://stackoverflow.com/questions/32334000/unresolved-external-symbol-c-vs-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!