Results 1 to 8 of 8

Thread: HELP- Linker error

  1. #1
    Zaei
    Guest
    You should re-install Visual Studio.

    Also,
    Code:
    void main
    {
    
    }
    is wrong. Use int main().

    Z.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It's not wrong, but it is bad habit.

    The linker error means that it can't find the debug version of the static C runtime library. As Zaei said: re-install VC++.
    In the installation, make sure you have these:
    Visual C++ -> Options:
    C runtime library -> Options:
    Static Single-Threaded Libraries
    Static Multi-Threaded Libraries
    Dynamic Libraries


    Not sure about the exact names, but you get the idea.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366

    OK, I will re-install

    Thanks a lot... I'll re-install it soon... I think you're right, maybe I mistakenly unchecked a Visual C++ runtime library.
    Another thing I wanted to ask was:
    Code:
    void main()
    {
    }
    I read somewhere that in C++ this is the way to do it, that you don't have to do:
    Code:
    int main()
    {
    return 0;
    }
    But if you say it is wrong / a bad habit, I guess I will do the second thing. In the other C++'s I thought the first piece of code was 'right,' and I assumed VC++ was the same...

  4. #4
    Zaei
    Guest
    parksie would disagree with you, CornedBee =). I think the logic is that some processors return from a function using the stack, instead of a register, and if you dont return something, things go wacky =(.

    Z.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Zaei, funny how you worked out what I'd say

    I checked closer, and the standard appears to be that int main is required, but you don't need a return statement (a compliant compiler will insert return 0, but it can only do that if it's defined to return an int).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366

    Thumbs up

    So, according to you people, the safest thing to do is:
    Code:
    int main()
    {
    return 0;
    }
    And that way, processors that can't handle void will be okay, and even if your compiler doesn't add a return 0;, it will be okay since you did.
    Correct?
    (Whoa! I started this thread because of a linker error and we're in to function return types. And we're discussing it in great detail...)
    Zaei you're a psychic... and thanks everyone... (Zaei, CornedBee, and I guess Parksie too, because of Zaei) for helping me.
    Last edited by DovyWeiss; Mar 5th, 2002 at 06:40 PM.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    As long as you only program for i386 cpus (the ones that are in ususal PCs) you won't have trouble with the void main(), but if you ever program other CPUs (like parksie does, this is the reason why he is so careful) you might get problems if you don't heed the standard.

    If the compiler doesn't insert "return 0;" then it will produce an error.
    BTW MSVC++ assumes that the function has return type "void" if you don't have a return statement, even if you specified another type.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366
    As I said before -- thanks, everyone, for all your help. I re-installed VC++ and included the libraries, and all is well...
    ...except that now I have a new problem with VB (not VC++). I need to know about files I need to distribute with my app...

    Please follow this link:
    http://www.vbforums.com/showthread.p...hreadid=149387

    Thanks a lot: Zaei, CornedBee (fancy new avatar just lately!) and Parksie too.

Posting Permissions

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



Click Here to Expand Forum to Full Width