未解析的外部符号,C++,VS 2015
Unresolved External symbol, C++, VS 2015
我已经阅读了 model answer on unresolved externals 并发现它非常有用,并且将其归结为最后两个我无法理解的顽固错误。
为了以防万一,我附上了所有代码,如果您想查看 headers 或其他任何内容,请说。
// 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");
}
我收到这些错误消息:
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
我已经检查了列表中的所有内容,试图找出这些错误的来源,并将其减少到只剩下这两个。
到目前为止尝试过的事情:
- 检查基本语法
- 检查并确保正确 headers 可用
- 查看了外部依赖项(但我真的不知道我在这里做什么)
- 查看了已尝试 here 但 none 有效的解决方案。
如有任何帮助,我们将不胜感激!
Unresolved External Symbols 意味着您的代码无法找到您尝试使用的方法或 class 的定义。这通常意味着发生了一件(或多件)事情:
- 您没有指向包含您正在使用的库的对象库(.lib Windows,.so Linux)的目录
- 您忘记在 linker 中指定您需要使用有问题的库(kernel32.lib、user32.lib、...的列表需要包含名称您正在使用的图书馆)
- 您尝试使用的库应该静态 link 编辑,而您正尝试动态 link 它(反之亦然)。检查图书馆的文档并确保您使用的是正确的表格。一些库希望包含或省略额外的 #define 语句,具体取决于您是 link 静态还是动态。
- 您更改了构建选项而忘记更新其他构建选项中的库。如果您设置为 Release 或 x64,请检查以确保您的构建选项在所有环境中都设置正确。
编辑: 我还将证实其他人在原始评论线程中所说的话:确保定义 Output() 和 dvector() 的代码是 link被你的代码访问了。
还有一些其他选项,但那些是最常出现的大选项。
我已经阅读了 model answer on unresolved externals 并发现它非常有用,并且将其归结为最后两个我无法理解的顽固错误。
为了以防万一,我附上了所有代码,如果您想查看 headers 或其他任何内容,请说。
// 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");
}
我收到这些错误消息:
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
我已经检查了列表中的所有内容,试图找出这些错误的来源,并将其减少到只剩下这两个。
到目前为止尝试过的事情:
- 检查基本语法
- 检查并确保正确 headers 可用
- 查看了外部依赖项(但我真的不知道我在这里做什么)
- 查看了已尝试 here 但 none 有效的解决方案。
如有任何帮助,我们将不胜感激!
Unresolved External Symbols 意味着您的代码无法找到您尝试使用的方法或 class 的定义。这通常意味着发生了一件(或多件)事情:
- 您没有指向包含您正在使用的库的对象库(.lib Windows,.so Linux)的目录
- 您忘记在 linker 中指定您需要使用有问题的库(kernel32.lib、user32.lib、...的列表需要包含名称您正在使用的图书馆)
- 您尝试使用的库应该静态 link 编辑,而您正尝试动态 link 它(反之亦然)。检查图书馆的文档并确保您使用的是正确的表格。一些库希望包含或省略额外的 #define 语句,具体取决于您是 link 静态还是动态。
- 您更改了构建选项而忘记更新其他构建选项中的库。如果您设置为 Release 或 x64,请检查以确保您的构建选项在所有环境中都设置正确。
编辑: 我还将证实其他人在原始评论线程中所说的话:确保定义 Output() 和 dvector() 的代码是 link被你的代码访问了。
还有一些其他选项,但那些是最常出现的大选项。