Thread: linker problems with VC++ for Win32 applications

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Unhappy linker problems with VC++ for Win32 applications

    hello everyone,
    I can create a new Win32 application and compile it, but when I come back later and try to alter the .cpp file, I get two linker errors, that I have no idea on how to fix. They state

    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/simplew.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    Does anyone have any idea on how to remedy this problem

    thank you to any repliers.
    - Paul Lucas (the Flucas)

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, you're not handling the WM_DESTROY message. Your program is still running even when you've "closed" the window.

    -Okay, try running the already compiled exe
    -"Close" the window
    -hit ctrl-alt-del and look at what programs are running
    -Chances are, yours is still there

    handle the WM_DESTROY message with the PostQuitMessage function (parameter 0) to exit the message loop and exit the program.

    Does this help?

    --Garfield the Pianist
    1978 Silver Anniversary Corvette

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Arrow to Garfield...

    thanks for your help, but I definately always make my Win32 applications with the WM_DESTROY in the Message handler. I still have no idea on how why I am recieving these linker errors (there are no compile errors). I am thinking of re-installing VC++ although I doubt that will achieve anything.
    - Paul Lucas (the Flucas)

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Did you do what I said? Did you see if your program was still running? I just recently had that same exact error.

    What else you could do:
    -study your WM_DESTROY message and make sure that it is doing the right code to exit the message loop or the program is still going to run.

    Post and/or attach your code and I'll test it on my computer.

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Make sure you have '/subsystem:windows' in your linker options.
    zen

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Flucas, is this your first Win32 program with MSVC? Because zen could be right if no other program is working.

    I thought you meant that it wasn't the first time, and it was your code. Sorry for the misunderstanding.

    --Garfield
    1978 Silver Anniversary Corvette

  7. #7
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    I had a simmilar problem doing a tutorial one time. My program wouldn't link in a project that I started as a win32 console app, had to use the regular win32 app project type, kinda sucks cause I had been using the console window to output values of different parameters to see what was going on behind the scenes.
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Exclamation

    argh!!! I tried everyone's suggestions but I still can't seem to combat the problem. Everytime I wanna compile my project I have to start a NEW Win32 Application project in VC++. Worst thing is that I'm only a beginner with Windows Programming so I have no idea how to fix the problem.

    Garfield, I did try your Idea to check if the prog was still running, it wasn't so its definately not the WM_DESTROY causing the trouble.

    I have 2 computers (with VC++ on both) and they both have the same linker problems. Does anyone have anymore Ideas as to why this is happening? Any help would be greatly appreciated

    - Paul Lucas

  9. #9
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    Try clicking the build menu, then Clean, see if you can link then.

    or Try doing a Console win32 App project, maybe it's the exact opposite of the problem I had.
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    How are you declaring your winmain()?

    The linker error 2001 usually means there is no 'main' function though one is called but does not exist. (Look for the 'main() undeclared assuming external returning int' warning ) Why it works first time I don't know. If you reset the PC in between runs does the problem fix itself?

    My WinMain() is
    int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdLine, int nCmdShow)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Your linker expects to see a main function. If you do Win32 programming, there is no main function as in Console programming. The easiest way is: Make a new empty Win32 Project, copy your files, include them into the project ( add files somewhere in the project menu ) and save this.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Wink THANK YOU ZEN!!!

    Hey Zen,
    thanks alot for your tip, u have cured the problem... thanks!!
    - Paul Lucas (the Flucas)

  13. #13
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    LIBCD.lib(crt0.obj) : error LNK2001

    I just had this same problem and cutting and pasting into a new project worked for me too. In my case I believe it comes from going straight to the c++ source file instead of creating a workspace first.

    Anyway, that is my hypothesis when I create apps. by first creating the project workspace this error doesn't occur.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parameter problems in C++ applications
    By burgerfrickle89 in forum C++ Programming
    Replies: 2
    Last Post: 07-06-2006, 03:04 PM
  2. More linker problems
    By Ganoosh in forum C++ Programming
    Replies: 4
    Last Post: 07-12-2005, 10:27 PM
  3. Linker Problems
    By Jason84 in forum C Programming
    Replies: 17
    Last Post: 09-14-2004, 02:52 PM
  4. Im having linking problems with turbo c++ ver 4.5
    By Marcos in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2004, 04:57 PM
  5. Please help with linker problems....
    By Michty in forum Windows Programming
    Replies: 1
    Last Post: 12-22-2003, 12:02 PM