未定义引用WinMain @ 16(代码块) [英] undefined reference to WinMain@16 (codeblocks)
问题描述
当我编译我的secrypt.cpp程序,我的编译器显示错误未定义的引用WinMain @ 16
。
我的代码如下
When I compile my secrypt.cpp program, my compiler shows the error "undefined reference to WinMain@16
".
my code is as follows
secrypt.h:
secrypt.h :
#ifndef SECRYPT_H
#define SECRYPT_H
void jRegister();
#endif
secrypt.cpp:
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";
}
trial.cpp
trial.cpp
#include<iostream>
#include "secrypt.h"
using namespace std;
int main()
{
void jRegister();
return 0;
}
这是我的错误的形象:
errorimage
Here is the image of my error: errorimage
当我编译我的trial.cpp程序,它编译和打开控制台,但没有调用该函数。这里是trial.cpp程序的控制台屏幕的图像。
o / p screen $
When I compile my trial.cpp program, it compiles and opens the console, but didn't calls the function. Here is the image of the console screen of trial.cpp program . o/p screen Can anyone help me solving this?
推荐答案
当没有项目时,Code :: Blocks只能编译和链接当前文件。该文件,从你的图片,是 secrypt.cpp
,它没有主要功能。为了编译和链接这两个源文件,您需要手动或将它们添加到同一个项目。
When there's no project, Code::Blocks only compiles and links the current file. That file, from your picture, is secrypt.cpp
, which does not have a main function. In order to compile and link both source files, you'll need to do it manually or add them to the same project.
与别人说的不同,使用Windows系统 main
仍然可以工作,控制台窗口。
Contrary to what others are saying, using a Windows subsystem with main
will still work, but there will be no console window.
您的其他尝试,编译和链接 trial.cpp
,从不链接 secrypt.cpp
。这通常会导致未定义的引用 jRegister()
,但是你已经声明了 main
调用它。更改主
为:
Your other attempt, compiling and linking just trial.cpp
, never links secrypt.cpp
. This would normally result in an undefined reference to jRegister()
, but you've declared the function inside main
instead of calling it. Change main
to:
int main()
{
jRegister();
return 0;
}
这篇关于未定义引用WinMain @ 16(代码块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!