VC++ 2010 Error

This is a discussion on VC++ 2010 Error within the C++ Programming forums, part of the General Programming Boards category; 1>------ Build started: Project: Test project 1, Configuration: Debug Win32 ------ 1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup 1>C:\Users\admin\documents\visual ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    14

    VC++ 2010 Error

    1>------ Build started: Project: Test project 1, Configuration: Debug Win32 ------
    1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
    1>C:\Users\admin\documents\visual studio 2010\Projects\Test project 1\Debug\Test project 1.exe : fatal error LNK1120: 1 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========





    This is my build report.
    its a very simple code to print hello world in an empty page , no precompiler header. what am i doing wrong?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Do you have a winMain () ?

    In which case, you have a GUI program, but you're using a console project.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    ^^ what Salem said.

    I'm guessing you want a console app -- you'll have to check your project type and make sure main() is defined.

    For pretty much everything, I use project type Visual C++/Win32/Win32 Console Application -- empty project, no precompiled headers.

    If you're trying to do a GUI program you should give some thought to how you want to do it, I've found .NET easier to work with than MFC. Either way, if you want to do that you probably shouldn't select 'empty project' -- MSVC generates a few files which you can fill in. That should include the right definition of main() or winMain()

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    14
    Its console application , and empty in Win32 , with void main().
    No Gui stuff.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,299
    Well void main would be one problem. main must always return int.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    It's odd actually... mainCRTStartup is the library function that calls main().

    Your linker error was
    error LNK2001: unresolved external symbol _mainCRTStartup

    I just tested the behaviour on my machine - a different error message is emitted when main is improperly specified.

    It seems like the linker is not pulling in all the libraries that it should. That feels like an installation problem -- maybe you didn't reboot when it asked you to? I know it does do some final environment setup after reboot.

    I'm actually using MSVC2008 but I don't think that will make any difference.

    Examining the linker's verbose output I see (in my successful build):
    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRTD.lib:
    Found _mainCRTStartup
    Loaded MSVCRTD.lib(crtexe.obj)

    I've attached my successful build output (rename it to .html, apparently I can't attach html files). You could enable verbose linker output in MSVC (Project->Properties->Linker Show progress=display all progress messages) then have a look at your output build log file and see where it's going wrong. I bet it's not scanning MSVCRTD.lib.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    14
    I went through the Win32 Wizard with an empty project , no precompiler. And did not get the link error. accepts the void main , but is not accepting the iostream.h library for some reason unknown to me.

  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Code:
    #include <iostream>
    ...
    using namespace std;
    Read why void main is wrong.

    MSVC++ accepts void main but it changes it to int main() during the compile phase to maintain C99 compliance. It just allows YOU NOT TO BE

    EDIT: If for no other reason then use int main so Salem won't obliterate you. Hint: I think it is a pet peeve.
    Last edited by AndrewHunter; 06-25-2011 at 05:13 PM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  10. #10
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    There's no iostream.h header on MSVC. You need to #include <iostream> (no .h).

  11. #11
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    As he was told by you in his other thread. If you really want to learn, Arpen Das, you need to pay careful attention to all the advice you are receiving.

    accepts the void main
    As *I* said in your other thread, while Microsoft's compiler will accept void main(), it is still wrong, as pointed out above. MS is simply hiding from you your failure to follow the standard and converting it to int main() silently. That's fine if you only ever write code in MSVC, but as soon as you try to compile in a stricter or more standards-conforming compiler, you're going to end up with errors.

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    14
    Hey , yes I started reading now , got accelerated c++ , going through it now. Will pick it up now I guess , thanks

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by Arpan Das View Post
    I went through the Win32 Wizard with an empty project , no precompiler. And did not get the link error. accepts the void main , but is not accepting the iostream.h library for some reason unknown to me.
    Do not create Win32 projects. Use console projects.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Error in Visual Studios 2010
    By ScottyK in forum C++ Programming
    Replies: 5
    Last Post: 11-21-2010, 11:54 AM
  2. Replies: 8
    Last Post: 10-25-2010, 11:43 PM
  3. 20/10/2010 20:10
    By Salem in forum General Discussions
    Replies: 10
    Last Post: 10-21-2010, 10:46 AM
  4. Replies: 2
    Last Post: 08-28-2010, 12:58 AM
  5. Windows 7 RC, Visual Studio 2010 Beta, Office 2010 beta, anyone in?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-20-2009, 01:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21