locked
Simple C++ Console Project Hello World program Wiil Not Build VS2010

    Question

  • Simple hello world app:

    #include <iostream>
    using namespace std;

    int main()
    {
         cout << "Hello world from  VS 2010!\n";
         return 0;
    }

    Build fails with linker errors.

    Any help or suggestions?

    FWIW, posted here as no applicable group is listed.

    Thursday, May 21, 2009 2:48 AM

Answers

  • Hello,

    This is an issue that has already been fixed post Beta 1. As mentioned above the workaround is either to rename main to wmain or alternatively change "Character Set" property (Project Properties > General) to be MBCS.

    Thanks,
    Marian Luparu
    Visual C++

    PS: We're currently working on getting the VC++ Beta forum up and running and we'll probaby move some of the C++ related threads to that forum as soon as it's live. Until then, responses from the team may be a little delayed. Sorry for the inconvenience.
    • Proposed as answer by Avery Lee Wednesday, May 27, 2009 4:02 AM
    • Marked as answer by pvdg42MVP Wednesday, May 27, 2009 1:19 PM
    Wednesday, May 27, 2009 3:10 AM
    Moderator
  • I never expected to see this old thread reappear, but when I placed your code in an *empty* C++ project in VS 2010, I got a syntax error on "end1". Once corrected to "endl", the build failed on a linker error due to failure to "find entry point".

    Once I corrected the function header to the standards compliant:

    int main(void)

    the project compiled fine. Why are you trying to use "_tmain"?

    Please note that this thread was started during *beta testing* of VS 2010, and was addressed and closed in the VS 2010 Release Candidate.

    • Marked as answer by pvdg42MVP Wednesday, June 09, 2010 2:46 PM
    Wednesday, June 09, 2010 2:46 PM

All replies

  • wmain?
    Thursday, May 21, 2009 6:13 AM
  • Are you suggesting that I use wmain () instead of main()?
    I'll try it, but if that is required, the new version has completely broken all ties to the ISO C++ specification, rendering VS 2010 unusable in a university classroom environment where ISO standard C++ is the subject. If that is the case, and nothing is done to restore compliance, Visual Studio will have to be removed from my department's list of development tools. I certainly hope this will not be the case.
    Thursday, May 21, 2009 12:20 PM
  • Confirmed that wmain() works, but *should not be necessary* in a standard C++ program in an *empty* console project!
    I have feedback from my bug indicating the issue "has been elevated..."
    Thursday, May 21, 2009 12:53 PM
  • I'll suggest you use _tmain instead main to get Ansi/Unicode auto cast in MSVC.
    most reason is type of argv different between main/wmain?
    Thursday, May 21, 2009 10:15 PM
  • Thanks, but the issue is not "can we work around the failure to build standard code". Rather, it is to ensure Microsoft is aware of the failure of the beta to properly handle standard code.

    Workarounds may be fine for private individual use,  but in a university environment where syllabi state that ISO standard C++ is taught, the failure is unacceptable.

    You may well feel that I'm being unnecessarily nitpicky, but from my perspective and responsibility, this is no minor issue. If we were to tell students to "just use wmain() instead", will the code compile on a Unix box or a Sun OS box? ISO standard C++ source code will.
    Friday, May 22, 2009 12:45 AM
  • Not to mention standards are standards for a reason. If they start breaking standards (again), we'll be back in the whole IE vs. standards compliant browsers issue (again), but for C++.
    Tuesday, May 26, 2009 10:57 PM
  • Hello,

    This is an issue that has already been fixed post Beta 1. As mentioned above the workaround is either to rename main to wmain or alternatively change "Character Set" property (Project Properties > General) to be MBCS.

    Thanks,
    Marian Luparu
    Visual C++

    PS: We're currently working on getting the VC++ Beta forum up and running and we'll probaby move some of the C++ related threads to that forum as soon as it's live. Until then, responses from the team may be a little delayed. Sorry for the inconvenience.
    • Proposed as answer by Avery Lee Wednesday, May 27, 2009 4:02 AM
    • Marked as answer by pvdg42MVP Wednesday, May 27, 2009 1:19 PM
    Wednesday, May 27, 2009 3:10 AM
    Moderator
  • I'm glad to hear that the problem has been addressed. I'll wait for the next beta or RC to confirm.
    Wednesday, May 27, 2009 1:20 PM
  • For additional information.

    Unicode character set by default: CLR Windows Forms application, MFC application, Win32 console application

    Multi-Byte character set by default: empty project.

    Friday, May 29, 2009 12:39 AM
  • FYI:  feedback issue on connect.microsoft.com is here :
    Monday, June 01, 2009 1:34 PM
  • There should be a project template that can compile standards compliant C++ without any errors.

    Can someone explain how to create such a template for VS2010 ?

    I tried to create a .vsz in theC:\Program Files\Microsoft Visual Studio 10.0\VC\vcprojects directory, and was able to set console and turn off managed code.  But I can't figure out how to set the character set to MBCS.  Here is what I tried:

    VSWIZARD 7.0
    Wizard=VsWizard.VsWizardEngine.10.0
    Param="WIZARD_NAME = Application"
    Param="RELATIVE_PATH = VCWizards\AppWiz\Generic"
    Param="CONSOLE_TYPE_ONLY = true"    <- does work
    Param="WIZARD_ID = 75"
    Param="MANAGED = FALSE"            <- does work
    Param="CHARACTERSET = MBCS"   <- does not work.

    in a file called cppconsole.vsz  It would be nice if there was some documentation that related the param names such as MANAGED to the project properties such as "Common Language Runtime Support". Then I could have a template that use the properties that I wanted instead of having to manually change them each time.

    • Edited by Andrew7Webb Wednesday, June 24, 2009 1:43 AM
    Tuesday, June 23, 2009 2:45 PM
  • Actually, this has been an educational process for me, As I originated the thread based on doing what I had always done in VS 2005 and VS 2008. If I had simply created an Empty Project in the C++ category, the issue I experienced would not have been an issue. I can't say a C++ Empty Project template won't have any issues, but it does work here for several dozen simple (student level) programs.
    Tuesday, June 23, 2009 5:50 PM
  • This is extactly what I did in Microsoft Visual Studio 2010:

     

    #include <iostream>

    using namespace std;

     

    int _tmain(void)

    {

    cout << "Hello Word" << end1; 

    return 0;

    }

     

    ERROR MESSAGE:

    1>------ Build started: Project: TEST, Configuration: Debug Win32 ------

    1>Build started 6/9/2010 4:44:10 AM.

    1>InitializeBuildStatus:

    1>  Touching "Debug\TEST.unsuccessfulbuild".

    1>ManifestResourceCompile:

    1>  All outputs are up-to-date.

    1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup

    1>C:\Users\doom11\documents\visual studio 2010\Projects\TEST_HELLOWORD!\Debug\TEST.exe : fatal error LNK1120: 1 unresolved externals

    1>

    1>Build FAILED.

    1>

    1>Time Elapsed 00:00:00.52

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

     

    And also, how do I resolve this linking issue? it gay, and it doesn't make sense!

    Wednesday, June 09, 2010 8:46 AM
  • I never expected to see this old thread reappear, but when I placed your code in an *empty* C++ project in VS 2010, I got a syntax error on "end1". Once corrected to "endl", the build failed on a linker error due to failure to "find entry point".

    Once I corrected the function header to the standards compliant:

    int main(void)

    the project compiled fine. Why are you trying to use "_tmain"?

    Please note that this thread was started during *beta testing* of VS 2010, and was addressed and closed in the VS 2010 Release Candidate.

    • Marked as answer by pvdg42MVP Wednesday, June 09, 2010 2:46 PM
    Wednesday, June 09, 2010 2:46 PM
  • Well, i am still getting the same error..........................

     

    1>  All outputs are up-to-date.

    1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup

    1>C:\Users\doom11\documents\visual studio 2010\Projects\TEST_HELLOWORD!\Debug\TEST.exe : fatal error LNK1120: 1 unresolved externals

     

    I even use main(void)..... wtf.

    Wednesday, June 09, 2010 3:19 PM
  • and also, I realized that it's required to have:

     

    #include "stdafx.h"

     

     

    int _tmain(int argc, _TCHAR* argv[])

    {

    return 0;

    }

     

    as a primary main, then I can add a new C++ file and then use the code:

     

    #include <iostream>

     

    int main(void)

    {

     

    std::cout << "Hello";

    return 0;

     

    }

     

    It build, it works.. however, when I start to debug the program, I get this following error messages:

     

    'test.exe': Loaded 'C:\Users\doom11\Documents\Visual Studio 2010\Projects\test\Debug\test.exe', Symbols loaded.

    'test.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file

    'test.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file

    'test.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file

    'test.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.

    The program '[2764] test.exe: Native' has exited with code 0 (0x0).


    Can anyone explain to me why? Thanks!!

    Wednesday, June 09, 2010 3:43 PM
  • I tried to fix this by going to debug--> optional and setting --debugging -->symbols and then enable: Microsoft Symbol Server. That still doesn't work.

     

     

    'test.exe': Loaded 'C:\Users\doom11\Documents\Visual Studio 2010\Projects\test\Debug\test.exe', Symbols loaded.

    'test.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).

    'test.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).

    'test.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).

    'test.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.

    The program '[920] test.exe: Native' has exited with code 0 (0x0).

    Wednesday, June 09, 2010 3:49 PM
  • Hi, If you want to debug, you may want to set a break point somewhere.

    if you would like the console window to pause after the run, you can set  Properties->Configuration Properties->Linker->System-> SubSytem to "Console (/SUBSYSTEM:CONSOLE)".

    Li Shao, MSFT


    Li Shao
    Wednesday, June 09, 2010 4:49 PM
  • Is debugging required? I tried to run the program without debugging and it wouldn't work, even a simple hello world doesn't. I checked my syntax and it's correct... /shrugs.
    Wednesday, June 09, 2010 4:54 PM
  • Well.. this is breaking the iso C++ standard..

     

    #include "stdafx.h"

    #include <iostream>

     

     

    int _tmain(int argc, _TCHAR* argv[])

    {

    std::cout << "test \n";

    return 0;

    }



    but it works.. :( unfortunately. 

    Wednesday, June 09, 2010 5:00 PM
  • hi

    i am having a problem in running this code

    program:

    sb.cpp

     

    // sb.cpp : Defines the entry point for the console application.

    //

     

    #include "stdafx.h"

     

     

     

     

    #include <cv.h>

    #include <cxcore.h>

    #include <highgui.h>

     

    int main( int argc, CHAR** argv[]) {

        cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );

        CvCapture* capture= cvCreateFileCapture("aa.avi" );

        IplImage* frame;

        while(1) {

            frame = cvQueryFrame( capture );

            if( !frame ) break;

            cvShowImage( "Example2", frame );

            char c = cvWaitKey(33);

            if( c == 27 ) break;

        }

        cvReleaseCapture( &capture );

        cvDestroyWindow( "Example2" );

    }

     

    when i compile :

     

     

    1>------ Build started: Project: sb, Configuration: Debug Win32 ------

    1>  Skipping... (no relevant changes detected)

    1>  sb.cpp

    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

     

     

    when i run:

     

     

    'sb.exe': Loaded 'C:\Documents and Settings\vishnu\My Documents\Visual Studio 2010\Projects\sb\Debug\sb.exe', Symbols loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\OpenCV2.1\bin\highgui210d.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Exports loaded.

    'sb.exe': Loaded 'C:\OpenCV2.1\bin\cxcore210d.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\avifil32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\msacm32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\msvfw32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\avicap32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\version.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\olepro32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\BricoPacks\Vista Inspirat 2\RocketDock\RocketDock.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\MSCTF.dll', Exports loaded.

    'sb.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'

    'sb.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', Exports loaded.

    'sb.exe': Loaded 'C:\OpenCV2.1\bin\opencv_ffmpeg210d.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\wsock32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\clbcatq.dll', Exports loaded.

    'sb.exe': Loaded 'C:\WINDOWS\system32\comres.dll', Exports loaded.

    The program '[2456] sb.exe: Native' has exited with code 0 (0x0).

     

    what is the problem in that ......... i cannot find this ..... help me

    Saturday, September 18, 2010 8:50 AM
  • Did you try to set a break point in your code to step through to see where the problem could be?

    Li Shao, MSFT


    Li Shao
    Monday, September 20, 2010 3:54 AM