当我编译我的 secrypt.cpp 程序时,我的编译器显示错误“ undefined reference to WinMain@16
”。我的代码如下
加密.h:
#ifndef SECRYPT_H
#define SECRYPT_H
void jRegister();
#endif
secrypt.cpp:
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include "secrypt.h"
using namespace std;
void jRegister()
{
ofstream outRegister( "useraccount.dat", ios::out );
if ( !outRegister ) {
cerr << "File could not be opened" << endl;
exit( 1 );}
string a,b,c,d;
cout<<"enter your username :";
cin>>a;
cout<<"enter your password :";
cin>>b;
outRegister<<a<<' '<<b<<endl;
cout<<"your account has been created";
}
试用版.cpp
#include<iostream>
#include "secrypt.h"
using namespace std;
int main()
{
void jRegister();
return 0;
}
这是我的错误图像: errorimage
当我编译我的 trial.cpp 程序时,它编译并打开控制台,但没有调用该函数。这是 trial.cpp 程序的控制台屏幕图像。 o/p screen 谁能帮我解决这个问题?
原文由 Jefree Sujit 发布,翻译遵循 CC BY-SA 4.0 许可协议
当没有项目时,Code::Blocks 只编译和链接当前文件。从您的图片来看,该文件是
secrypt.cpp
,它没有主要功能。为了编译和链接两个源文件,您需要手动完成或将它们添加到同一个项目中。与其他人所说的相反,使用带有
main
的 Windows 子系统仍然可以工作,但不会有控制台窗口。您的其他尝试,仅编译和链接
trial.cpp
,从不链接secrypt.cpp
。这通常会导致对jRegister()
的未定义引用,但是您已经在main
中声明了该函数,而不是调用它。将main
更改为: