| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1952 人关注过本帖
标题:希望大家能够看看这个程序,它的报错很特别,我看不懂
只看楼主 加入收藏
renhu
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-11-27
收藏
 问题点数:0 回复次数:6 
希望大家能够看看这个程序,它的报错很特别,我看不懂

#include<iostream>
#include<math.h>
#include<vector>

using namespace std;

class findroot{
private:
double a,b,c,d,x1,x2;
public:
findroot(double x,double y,double z);
void find();
void display();
};

class seqlist{
private:
int num;
char name[10];
public:
int getnum(){return num;}
void dispname(){cout<<name;}
void setnum(int a){num=a;}
void setname(char b[]){strcpy(name,b);}
};

void findit();
void handle_menu(void);
int menu_select();

void game1();
void game2();

void joseph(seqlist [],int);
void joseph(vector<seqlist>&);


findroot::findroot(double x,double y,double z)
{
a=x;b=y;c=z;
d=b*b-4*a*c;
}

void findroot::find()
{
if(d>0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
return;
}
else if(d==0)
{
x1=x2=-b/(2*a);
return;
}
else
{
x1=-b/(2*a);
x2=sqrt(-d)/(2*a);
}
}

void findroot::display()
{
if(d>0)
{
cout<<"x1="<<x1<<"\nx2="<<x2<<endl;
return;
}
else if(d==0)
{
cout<<"x1=x2="<<x1<<endl;
return;
}
else
{
cout<<"x1="<<x1<<"+"<<x2<<"i"<<endl;
cout<<"x2="<<x1<<"-"<<x2<<"i"<<endl;
}
}

void fintit()
{
double a,b,c;
cout<<"这是个求方程ax2+bx+c=0的根的程序。"<<endl;
for(;;)
{
cout<<"输入方程系数a:";
cin>>a;
if(a==0)
{
getchar();
return;
}
cout<<"输入方程系数b:";
cin>>b;
cout<<"输入方程系数c:";
cin>>c;
findroot obj(a,b,c);
obj.find();
obj.display();
}
}

void joseph(seqlist c[],int length)
{
int m;
cout<<"please input first interval m(m<=20)";
cin>>m;
while(m>20)
{
cout<<"it is too large.please input another number:\n";
cin>>m;
}
cout<<"please input code:"<<endl;
getchar();

char s[10];
for(int i=0;i<length;i++)
{
cout<<"no"<<i+1<<"个人的名字:";
gets(s);
c[i].setname(s);
}
i=-1;
int j,k;
for(k=1;k<=length;k++)
{
j=0;
while(j<m)
{
i++;
if(i==length)
i=0;
if(c[i].getnum()!=0) j++;
}
if(k==length) break;
c[i].dispname();
cout<<",";

c[i].setname(0);
}
c[i].dispname();
cout<<endl;
}
void game1()
{
const int n=30;

int length=0;
cout<<"please input the munber of people:";
cin>>length;
seqlist c[n];
for(int i=0;i<length;i++)
{
c[i].setnum(i+1);
c[i].setname(" ");
}
joseph(c,length);
}

void game2()
{


int length=0;
cout<<"please input the munber of people:";
cin>>length;
vector<seqlist>c(length);
for(int i=0;i<length;i++)
{
c[i].setnum(i+1);
c[i].setname(" ");
}
joseph(c);
}

void joseph(vector<seqlist>&c)
{
int m;
cout<<"please input first interval m(m<=20)";
cin>>m;
while(m>20)
{
cout<<"it is too large.please input another number:\n";
cin>>m;
}
cout<<"please input code:"<<endl;
getchar();

char s[10];
for(int i=0;i<c.size();i++)
{
cout<<"no"<<i+1<<"个人的名字:";
gets(s);
c[i].setname(s);
}
i=-1;
int j,k;
vector<seqlist>::iterator p;
p=c.begin();
int length=c.size();
for(k=1;k<=length;k++)
{
j=0;
while(j<m)
{
i++;
if(i==c.size())
i=0;
j++;
}


if(k==length) break;
c[i].dispname();
cout<<",";

c.erase (p+i);
--i;
}
c[i].dispname();
cout<<endl;
}


void main()
{
handle_menu();
}

void handle_menu(void)
{
for(;;)
{
switch(menu_select())
{
case 1:
findit();
break;
case 2:
game1();
break;
case 3:
game2();
break;
case 4:
cout<<"\t再见!\n";
return;
}
}
}

int menu_select()
{
char s[2];
int cn;

cout<<"\t1.解一元二次方程\n";
cout<<"\t2.出圈游戏之一\n";
cout<<"\t3.出圈游戏之二\n";
cout<<"\t4.退出程序\n";
cout<<"\t选择1-4: ";

for(;;)
{
gets(s);
cn=atoi(s);
if(cn<1||cn>4)
printf("\n\t输入错误,重选1-4: ");
else
break;
}
return cn;
}


--------------------Configuration: practic2 - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "void __cdecl findit(void)" (?findit@@YAXXZ)
Debug/practic2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

practic2.exe - 2 error(s), 0 warning(s)




搜索更多相关主题的帖子: double void include name 
2005-12-07 23:21
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
我用Borland C++5.5都没编译过去。

Error E2451 027.cpp 126: Undefined symbol 'i' in function joseph(seqlist *,int)

Warning W8012 027.cpp 193: Comparing signed and unsigned values in function jose
ph(vector<seqlist,allocator<seqlist> > &)

Error E2451 027.cpp 199: Undefined symbol 'i' in function joseph(vector<seqlist,allocator<seqlist> > &)

Error E2285 027.cpp 220: Could not find a match for 'vector<seqlist,allocator<seqlist> >::erase(undefined)' in function joseph(vector<seqlist,allocator<seqlist>> &)

Warning W8004 027.cpp 225: 'p' is assigned a value that is never used in functio
n joseph(vector<seqlist,allocator<seqlist> > &)

[此贴子已经被作者于2005-12-8 9:50:29编辑过]


成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2005-12-08 09:49
yongke33
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-12-4
收藏
得分:0 
你的程序 我看过了 在VC上 也不能运行
2005-12-08 23:35
abcba
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-11-11
收藏
得分:0 

Linker Tools Error LNK2001

unresolved external symbol "symbol"

Code will generate this error message if it references something (like a function, variable, or label) that the linker can’t find in all the libraries and object files it searches. In general, there are two reasons this error occurs: what the code asks for doesn’t exist (the symbol is spelled incorrectly or uses the wrong case, for example), or the code asks for the wrong thing (you are using mixed versions of the libraries?some from one version of the product, others from another version).

Numerous kinds of coding and build errors can cause LNK2001. Several specific causes are listed below, and some have links to more detailed explanations.

Coding Problems

  • Mismatched case in your code or module-definition (.DEF) file can cause LNK2001. For example, if you named a variable “var1” in one C++ source file and tried to access it as “VAR1” in another, you would receive this error. The solution is to exactly match the case of the symbol in all references.

  • A project that uses function inlining yet defines the functions in a .CPP file rather than in the header file can cause LNK2001.

  • If you are using C++, make sure to use extern “C” when calling a C function from a C++ program. By using extern “C” you force the use of the C naming convention. Be aware of compiler switches like /Tp or /Tc that force a file to be compiled as a C (/Tc) or C++ (/Tp) file no matter what the filename extension, or you may get different function names than you expect.

  • Attempting to reference functions or data that don't have external linkage causes LNK2001. In C++, inline functions and const data have internal linkage unless explicitly specified as extern.

  • A missing function body or variable will cause LNK2001. Having just a function prototype or extern declaration will allow the compiler to continue without error, but the linker will not be able to resolve your call to an address or reference to a variable because there is no function code or variable space reserved.

  • Name decoration incorporates the parameters of a function into the final decorated function name. Calling a function with parameter types that do not match those in the function declaration may cause LNK2001.

  • Incorrectly included prototypes will cause the compiler to expect a function body that is not provided. If you have both a class and non-class implementation of a function F, beware of C++ scope-resolution rules.

  • When using C++, make sure that you include the implementation of a specific function for a class and not just a prototype in the class definition.

  • Attempting to call a pure virtual function from the constructor or destructor of an abstract base class will cause LNK2001 since by definition a pure virtual function has no base class implementation.

  • Only global functions and variables are public.

    Functions declared with the static modifier by definition have file scope. Static variables have the same limitation. Trying to access any static variables from outside of the file in which they are declared can result in a compile error or LNK2001.

    A variable declared within a function (a local variable) can only be used within the scope of that function.

    C++ global constants have static linkage. This is different than C. If you try to use a global constant in C++ in multiple files you get error LNK2001. One alternative is to include the const initializations in a header file and include that header in your .CPP files when necessary, just as if it was a function prototype. Another alternative is to make the variable non-constant and use a constant reference when assessing it.

Compiling and Linking Problems

  • The names of the Microsoft run-time and MFC libraries needed at link time are included in the object file module by the Microsoft compiler. If you use the /NOD (/NODEFAULTLIB) option, these libraries will not be linked into the project unless you have explicitly included them. Using /NOD will cause error LNK2001 in this case.

  • If you are using Unicode and MFC, you will get an unresolved external on _WinMain@16 if you don’t create an entrypoint to wWinMainCRTStartup. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.) See Unicode Programming Summary.

    See the following Knowledge Base articles located in the Online Information System for more information. An easy way to reach an article is to copy a "Q" number above, open the Search dialog box from the Help menu and select the Query tab, then paste the number into the first text box and press ENTER.
    • Q125750 "PRB: Error LNK2001: '_WinMain@16': Unresolved External Symbol"

    • Q131204 "PRB: Wrong Project Selection Causes LNK2001 on _WinMain@16"

    • Q100639 "Unicode Support in the Microsoft Foundation Class Library"
  • Linking code compiled with /MT with the library LIBC.LIB causes LNK2001 on _beginthread, _beginthreadex, _endthread, and _endthreadex.

  • When compiling with /MD, a reference to "func" in your source becomes a reference "__imp__func" in the object since all the run-time is now held within a DLL. If you try to link with the static libraries LIBC.LIB or LIBCMT.LIB, you will get LNK2001 on __imp__func. If you try to link with MSVCxx.LIB when compiling without /MD you will not always get LNK2001, but you will likely have other problems.

  • Linking code compiled with an explicit or implicit /ML to the LIBCMT.LIB causes LNK2001 on _errno.

  • Linking with the release mode libraries when building a debug version of an application can cause LNK2001. Similarly, using an /Mxd option (/MLd, /MTd, or /MDd) and/or defining _DEBUG and then linking with the release libraries will give you potential unresolved externals (among other problems). Linking a release mode build with the debug libraries will also cause similar problems.

  • Mixing versions of Microsoft libraries and compiler products can be problematic. A new compiler version's libraries may contain new symbols that cannot be found in the libraries included with previous versions. Use DUMPBIN to find out if a symbol is in a 32-bit object file or library.

  • There is currently no standard for C++ naming between compiler vendors or even between different versions of a compiler. Therefore linking object files compiled with other compilers may not produce the same naming scheme and thus cause error LNK2001.

  • Mixing inline and non-inline compile options on different modules can cause LNK2001. If a C++ library is created with function inlining turned on (/Ob1 or /Ob2) but the corresponding header file describing the functions has inlining turned off (no inline keyword), you will get this error. To prevent this problem, have the inline functions defined with inline in the header file you are going to include in other files.

  • If you are using the #pragma inline_depth compiler directive, make sure you have a value of 2 or greater set, and make sure you are using the /Ob1 or /Ob2 compiler option.

  • Omitting the LINK option /NOENTRY when creating a resource-only DLL will cause LNK2001.

  • Using incorrect /SUBSYSTEM or /ENTRY settings can cause LNK2001. For example, if you write a character-based application (a console application) and specify /SUBSYSTEM:WINDOWS, you will get an unresolved external for WinMain. For more information on these options and entry points, see the /SUBSYSTEM and /ENTRY linker options.

Export Problems

  • When you are porting an application from 16 to 32 bits, LNK2001 can occur. The current 32-bit module-definition (.DEF) file syntax requires that __cdecl, __stdcall, and __fastcall functions be listed in the EXPORTS section without underscores (undecorated). This differs from the 16-bit syntax, where they must be listed with underscores (decorated). For more information, see the description of the EXPORTS section of module-definition files.

  • Any export listed in the .DEF file and not found will cause LNK2001. This could be because it does not exist, is spelled incorrectly, or uses decorated names (.DEF files do not take decorated names).

This error message is followed by fatal error LNK1120.

[此贴子已经被作者于2005-12-9 10:38:51编辑过]

2005-12-09 10:30
abcba
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-11-11
收藏
得分:0 

Linker Tools Error LNK1120

number unresolved externals

Error LNK1120 gives you a count (number) of unresolved externals for this link. The conditions that cause unresolved externals are described with error LNK2001, which precedes this error message (once for each unresolved external).

2005-12-09 10:30
abcba
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-11-11
收藏
得分:0 

看不懂就先下个金山词霸慢慢看好了

[此贴子已经被作者于2005-12-9 10:33:12编辑过]

2005-12-09 10:31
abcba
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-11-11
收藏
得分:0 
[转]

学习VC++时经常会遇到链接错误LNK2001,该错误非常讨厌,因为对于编程者来说,最好改的错误莫过于编译错误,而一般说来发生连接错误时,编译都已通过。产生连接错误的原因非常多,尤其LNK2001错误,常常使人不明其所以然。如果不深入地学习和理解VC++,要想改正连接错误LNK2001非常困难。

  初学者在学习VC++的过程中,遇到的LNK2001错误的错误消息主要为:

  unresolved external symbol “symbol”(不确定的外部“符号”)。

  如果连接程序不能在所有的库和目标文件内找到所引用的函数、变量或标签,将产生此错误消息。一般来说,发生错误的原因有两个:一是所引用的函数、变量不存在、拼写不正确或者使用错误;其次可能使用了不同版本的连接库。

  以下是可能产生LNK2001错误的原因:

  一.由于编码错误导致的LNK2001。

  1.不相匹配的程序代码或模块定义(.DEF)文件能导致LNK2001。例如,如果在C++ 源文件内声明了一变量“var1”,却试图在另一文件内以变量“VAR1”访问该变量,将发生该错误。

  2.如果使用的内联函数是在.CPP文件内定义的,而不是在头文件内定义将导致LNK2001错误。

  3.调用函数时如果所用的参数类型同函数声明时的类型不符将会产生LNK2001。

  4.试图从基类的构造函数或析构函数中调用虚拟函数时将会导致LNK2001。

  5.要注意函数和变量的可公用性,只有全局变量、函数是可公用的。

  静态函数和静态变量具有相同的使用范围限制。当试图从文件外部访问任何没有在该文件内声明的静态变量时将导致编译错误或LNK2001。

  函数内声明的变量(局部变量) 只能在该函数的范围内使用。

  C++的全局常量只有静态连接性能。这不同于C,如果试图在C++的多个文件内使用全局变量也会产生LNK2001错误。一种解决的方法是需要时在头文件中加入该常量的初始化代码,并在.CPP文件中包含该头文件;另一种方法是使用时给该变量赋以常数。

  二.由于编译和链接的设置而造成的LNK2001

  1.如果编译时使用的是/NOD(/NODEFAULTLIB)选项,程序所需要的运行库和MFC库在连接时由编译器写入目标文件模块, 但除非在文件中明确包含这些库名,否则这些库不会被链接进工程文件。在这种情况下使用/NOD将导致错误LNK2001。

  2.如果没有为wWinMainCRTStartup设定程序入口,在使用Unicode和MFC时将得到“unresolved external on _WinMain@16”的LNK2001错误信息。

  3.使用/MD选项编译时,既然所有的运行库都被保留在动态链接库之内,源文件中对“func”的引用,在目标文件里即对“_imp__func” 的引用。

  如果试图使用静态库LIBC.LIB或LIBCMT.LIB进行连接,将在__imp__func上发生LNK2001;如果不使用/MD选项编译,在使用MSVCxx.LIB连接时也会发生LNK2001。

  4.使用/ML选项编译时,如用LIBCMT.LIB链接会在_errno上发生LNK2001。

  5.当编译调试版的应用程序时,如果采用发行版模态库进行连接也会产生LNK2001;同样,使用调试版模态库连接发行版应用程序时也会产生相同的问题。

  6.不同版本的库和编译器的混合使用也能产生问题,因为新版的库里可能包含早先的版本没有的符号和说明。

  7.在不同的模块使用内联和非内联的编译选项能够导致LNK2001。如果创建C++库时打开了函数内联(/Ob1或/Ob2),但是在描述该函数的相应头文件里却关闭了函数内联(没有inline关键字),这时将得到该错误信息。为避免该问题的发生,应该在相应的头文件中用inline关键字标志内联函数。

  8.不正确的/SUBSYSTEM或/ENTRY设置也能导致LNK2001。

  其实,产生LNK2001的原因还有很多,以上的原因只是一部分而已,对初学者来说这些就够理解一阵子了。但是,分析错误原因的目的是为了避免错误的发生。LNK2001错误虽然比较困难,但是只要注意到了上述问题,还是能够避免和予以解决的。

2005-12-09 11:33
快速回复:希望大家能够看看这个程序,它的报错很特别,我看不懂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013217 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved