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?
This question is related to
c++
windows
codeblocks
You need to open the project file of your program and it should appear on Management panel.
Right click on the project file, then select add file. You should add the 3 source code (secrypt.h, secrypt.cpp, and the trial.cpp)
Compile and enjoy. Hope, I could help you.
I was interested in setting up graphics for Code Blocks when I ran into a this error: (took me 2 hrs to solve it)
I guess you need to have a bit of luck with this. In my case i just changed the order of contents in Settings menu->Compiler and Debugger->Global compiler settings->Linker settings->Other Linker Options: The working sequence is: -lmingw32 -lSDL -lSDLmain
Open the project you want to add it.
Right click on the name.
Then select, add in the active project.
Then the cpp
file will get its link to cbp
.
I had the same error problem using Code Blocks rev 13.12. I may be wrong here since I am less than a beginner :)
My problem was that I accidentally capitalized "M" in Main() instead of ALL lowercase = main() - once corrected, it worked!!!
I noticed that you have "int main()" instead of "main()". Is this the problem, or is it supposed to be that way?
Hope I could help...
You should create a new project in Code::Blocks, and make sure it's 'Console Application'.
Add your .cpp files into the project so they are all compiled and linked together.
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 .
Source: Stackoverflow.com