LNK2019: unresolved external symbol "void __cdel referencd in function _main
本帖最后由 sfxyz7 于 2013-10-05 11:30:47 编辑 //main.cpp
#include <iostream>
using namespace std;
void GetStudentInfo();
int main()
{
GetStudentInfo();
return 0;
}
//stdinfo.cpp
//stud是结构体
void GetStudentInfo()
{
int i=1;
ifstream in("stdinfo.txt");
if(!in)
{
cout<<"ERROR_OPEN_STDINFO"<<endl;
exit(0);
}
string str;
while(getline(in,str))
{
stud[i].stdID = str.substr(0,10);
stud[i].classNum = atoi(str.substr(10,1).c_str());
stud[i].name = str.substr(11,str.length()-11);
stud[i].subID = atoi(str.substr(6,4).c_str());
i++;
}
}
然后编译的时候会出现如下错误:
LNK2019: unresolved external symbol "void __cdecl GetStudentInfo(void)" (?GetStudentInfo@@YAXXZ) referenced in function _main
如果把GetStudentInfo()里面的内容放在主函数里面就不会出现这个问题,该怎么解决啊? LNK2019 ?function?_main void?__cdecl?
[解决办法]
main.cpp中函数申请加个extern void GetStudentInfo();
[解决办法]
1楼说的方法是其一
也可以再加一个stdinfo.h文件的里面加上void GetStudentInfo()函数的申明
然后再main.cpp和stdinfo.cpp中 分别 #include "stdinfo.h"
[解决办法]
文件stdinfo.cpp
编译没有通过,所以:
LNK2019: unresolved external symbol "void __cdecl GetStudentInfo(void)" (?GetStudentInfo@@YAXXZ) referenced in function _main
一个可能是,stdinfo.cpp里面,没有以下语句中的一个
#include <iostream>
#include <fstream>
using namespace std;
[解决办法]
你先看看你的stdinfo.cpp在不在工程文件里。
[解决办法]
文件stdinfo.cpp
编译没有通过,所以:
LNK2019: unresolved external symbol "void __cdecl GetStudentInfo(void)" (?GetStudentInfo@@YAXXZ) referenced in function _main
一个可能是,stdinfo.cpp里面,没有以下语句中的一个
#include <iostream>
#include <fstream>
using namespace std;
有这些,今天在另外一个机器上没有出现这些问题,貌似是盗版的问题
你先看看你的stdinfo.cpp在不在工程文件里。
++
这是另一个可能。
貌似是盗版的问题?
那买个正版吧!
[解决办法]
main.cpp中函数申请加个extern void GetStudentInfo();
函数声明默认是extern的。