当我编译 secrypt.cpp 程序时,我的编译器显示错误“undefined reference to WinMain@16
”。
我的代码如下
加密.h:
#ifndef SECRYPT_H
#define SECRYPT_H
void jRegister();
#endif
加密.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;
}
这是我的错误的图像:错误图像
当我编译 Trial.cpp 程序时,它会编译并打开控制台,但不会调用该函数。这是 Trial.cpp 程序的控制台屏幕的图像。输出屏幕谁能帮我解决这个问题吗?
当没有项目时,Code::Blocks 只编译并链接当前文件。从你的图片来看,该文件是secrypt.cpp
,它没有主要功能。为了编译和链接这两个源文件,您需要手动执行或将它们添加到同一项目中。
与其他人所说的相反,使用 Windows 子系统main
仍然可以工作,但不会有控制台窗口。
您的其他尝试,编译和链接只是trial.cpp
,从不链接secrypt.cpp
。这通常会导致未定义的引用jRegister()
,但你已经在里面声明了该函数main
而不是调用它。改变main
to:
int main()
{
jRegister();
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)