C++中出现未解决的外部变量,是什么原因?

来源:百度知道 编辑:UC知道 时间:2024/05/28 09:55:31
--------------------Configuration: 实验一 - Win32 Debug--------------------

Compiling...
实验一.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/实验一.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

实验一.exe - 1 error(s), 0 warning(s)
用牛顿迭代法求方程的2*x*x*x-4*x*x+3*x-6=0解
#include <iostream.h>
#include <stdio.h>
#include <math.h>
int main()
{
float x,x0,d,f,fd;
x0=0;
do {
f=2*x0*x0*x0-4*x0*x0+3*x0-6;
fd=6*x0*x0-8*x0+3;
d=f/fd;
x=x0-d;
x0=x;
}while(fabs(d)>1e-3);
printf("x=%f\n",x);
return 0;
}

看样子你新建的是Win32工程,写的code却是console的。

新建项目->console application[没用C++,不知道是不是这样写]
然后将上面的.cpp文件add进去,编译运行即可!

如果代码没问题的前提下:

选择-Project(工程)-settings(设定)-Use MFC in a Shared dll
试试

最好发上代码看看

很明显,工程建错了,你应该选择win32 console application

你把工程弄错了