0

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!

Community
  • 1
  • 1
zephyr9581
  • 3
  • 1
  • 3
  • Well, where is this "Output()" function defined that you reference? – OldProgrammer Sep 01 '15 at 14:21
  • @zephyr9581 Not how but where. There is no declaration for the `Output()` function in your posted code. – NathanOliver Sep 01 '15 at 14:25
  • I declare it in the main program: void CDE(double), AB(void), Output(void); and then define it later: Output(); Is that what you mean? – zephyr9581 Sep 01 '15 at 14:26
  • @zephyr9581 Where is the code for the `Ouput()` function? just doing `void Output(void);` is not enough. – NathanOliver Sep 01 '15 at 14:28
  • `Output();` is a call to the function not a definition. A definition is like what `main()` looks like. – Ross Bencina Sep 01 '15 at 14:31
  • @zephyr9581 Think about it. Pretend you're the computer running your program. You get to the line where you say `Output();`, so that function is called *an executed*. But where is it? What are its steps? That's what the linker is telling you -- you're calling a function, but it doesn't really exist. A header file only tells the compiler that "a function exists out there somewhere" -- there may not be such a function, but the compiler trusts you. When it comes time to link, that is when your function will be checked for existance. – PaulMcKenzie Sep 01 '15 at 14:40

1 Answers1

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.

Xirema
  • 19,889
  • 4
  • 32
  • 68
  • Ah thank you! So i have a linking error and i need to find the object library? You say 'in the linker' where do i find this and how would i point to the correct library? – zephyr9581 Sep 01 '15 at 14:47
  • Project-->Properties-->Configuration Properties-->Linker-->(General, Input)-->(Additional Library Directories, Additional Dependencies) and check that those are set correctly. – Xirema Sep 01 '15 at 14:51
  • @Xirema You forgot `5.`, and that is the programmer plain old didn't write or forgot to write the missing function. – PaulMcKenzie Sep 01 '15 at 15:08
  • My edit was meant to allude to that possibility. – Xirema Sep 01 '15 at 15:10
  • 1
    Haha thanks i did have that earlier on (its downloaded code and one of them was missing) but i think its now me being a novice and not linking correctly; sorry for the 20 questions but how do i find the .lib created? It says that it while be made after the 'build solution' but the build doesn't work due to these errors so i don't know what lib i'm using? – zephyr9581 Sep 01 '15 at 15:15