When I compile my secrypt.cpp program, my compiler shows the error "undefined reference to WinMain@16
".
my code is as follows
secrypt.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";
}
trial.cpp
#include<iostream>
#include "secrypt.h"
using namespace std;
int main()
{
void jRegister();
return 0;
}
Here is the image of my error: errorimage
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?
The error means that the compiler try to find WinMain() but it didn't. Either you didn't declare int main() Or your project type is something other than Console. ( Normally Win32GUI) 20th Oct 2020, 10:52 AM.
WinMain@16 is referring to the "real" entry point of a windows exe. In a console application this is provided by C-runtime library. The first thing I would look at is that you are telling your compiler to build a console app.
How To Fix Undefined Reference in C++ You can fix undefined reference in C++ by investigating the linker error messages and then providing the missing definition for the given symbols. Note that not all linker errors are undefined references, and the same programmer error does not cause all undefined reference errors.
An “Undefined Reference” error occurs when we have a reference to object name (class, function, variable, etc.) in our program and the linker cannot find its definition when it tries to search for it in all the linked object files and libraries.
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.
Contrary to what others are saying, using a Windows subsystem with main
will still work, but there will be no console window.
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;
}
Well I know this answer is not an experienced programmer's approach and of an Old It consultant , but it worked for me .
the answer is "TRY TURNING IT ON AND OFF" . restart codeblocks and it works well reminds me of the 2006 comedy show It Crowd .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With