-
C Problem
i have a problem i do not either undestand or know how to solve..
i am using visual c++ 6 ( i am new to c++)
considering the following simple code
#include <fstream.h>
#include <iostream.h>
int main(void)
{
ofstream my_file("c:\test.txt");
my_file<<"This text will now be inside of test.txt";
my_file.close();
return 0;
}
the compilation goes fine
but when i try to build the exe i get the following:
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Hello3.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
could anyone tell me what's going on? thanx in advance
-
I don't actually know c, but I do more or less know php, and I was thinking it might be because your Doesn't end with a semicolon, ;
Hope this helps
-
The error is in the linker. The way I fixed this problem was to open a new project in VC++ and paste the old code and recompile it. I have no idea why it does this, and I know for a fact there are others that know the linker error codes.
ammo, any ideas?
-
Quote:
Originally posted here by khakisrule
I don't actually know c, but I do more or less know php, and I was thinking it might be because your Doesn't end with a semicolon, ;
Hope this helps
im pretty sure that int main(void) doesnt end with a semicolon since it isn't a statement. I could be wrong, im new to c, and recently read that only statements end with the semicolon. Other than that, i dont know the error, you might wanna ask ammo, he is the programming king. or rioter, hes good too.
-
putting a ; after int main(void) would not be correct thing to do. It has been a while but I think either you are missing an include file or you have called a external function by an incorrect name. It has been a very long time since I did C though.
-
thats right, int main(void) does not to have a semicolon, only if it is your function prototype which it isnt.
Does your compiler come with help files? Some compilers come with documentation of compile and link errors.
I did a web search for you and this site http://www.cs.northwestern.edu/acade...html/bugs.html apears to have an answer for you. I simply did a search for
"LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
"
with the quotes.
I copyed the folowing from the area of the site:
============================================
Linker error "unresolved external symbol _WinMain@16"
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
tests___Win32_Debug/tests.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
You have named your source file name.cpp . Rename it to name.c
You have created the wrong type of project. Create a Win32 Application for graphics and a Win32 Console Application for projects with no graphics.
-
Hey, that was a great find, I always wondered about the error messages, and was not all that clear even on MSDN. I will give the link to the C++ teacher...
-
Make sure it is a console app and not a windows app. This is done in the project settings.
Cheers,
-D
and it should be
int main()
{
or
int main (int charc, char* argv[])
{
either way no ; -thought I'd [pound the dead horse
-
Like the others said, you probably created the wrong type of project with Visual C++....
Make sure you create a console app...
Ammo
BTW, you should have said a "C++ problem" as your code is C++...