Results 1 to 9 of 9

Thread: C Problem

  1. #1

    Angry 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

  2. #2
    I don't actually know c, but I do more or less know php, and I was thinking it might be because your
    int main(void)
    Doesn't end with a semicolon, ;
    Hope this helps

  3. #3
    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?

  4. #4
    er0k
    Guest
    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.

  5. #5
    Junior Member
    Join Date
    Jul 2002
    Posts
    14
    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.

  6. #6
    Senior Member
    Join Date
    Jun 2002
    Posts
    148
    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.
    In snatches, they learn something of the wisdom
    which is of good, and more of the mere knowledge which is of evil. But must I know what must not come, for I shale become those of knowledgedome. Peace~

  7. #7
    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...

  8. #8
    Senior Member
    Join Date
    Jul 2001
    Posts
    420
    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
    If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
    -- former White House cybersecurity adviser Richard Clarke

  9. #9
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    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++...
    Credit travels up, blame travels down -- The Boss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •