Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ problem.

Options
  • 16-01-2013 4:01pm
    #1
    Registered Users Posts: 2,066 ✭✭✭


    Hi Folks,

    I've decided to teach myself C++. I'm working from this site here it seems reasonable good.

    Anyways, yesterday I downloaded Microsoft Visual C++ 2010 version and went t oexecute run my first program Hello World and I ran into problems.

    I can compile the program fine with no errors but when I go to run it I get this message:

    Unable to start program ‘C:Users\Visual Studio 2010\Projects\debug\Helloworld.dll’

    Here’s the program code:

    // Helloworld2.cpp : Defines the exported functions for the DLL application.
    //

    #include "stdafx.h"
    #include <iostream>

    int main()

    { std::cout << "Hello world!" << std::endl;
    return 0;

    }


    I would be grateful if anyone could help it with this. Learning C++ is my New Year resolution and I don't want to give up already. :)

    Also note I'm not one bit tech savy so simple english please.


Comments

  • Closed Accounts Posts: 8,016 ✭✭✭CreepingDeath


    My C++ is about 15 years rusty, but looks like you're trying to compile/build your code as a DLL instead of a command line application.


  • Registered Users Posts: 2,426 ✭✭✭ressem


    As CreepingDeath says...

    In Visual Studio, in the top menu, click
    "Project > Properties"

    This brings up the "Property pages" dialog.
    On the left menu panel click "Configuration Properties > General"

    The right panel should now contain a list of settings for
    "General" and "Project Defaults" properties.
    In the "Project Defaults" section the first entry should be the "Configuration Type" and you seem to have it set to "Dynamic Library(.dll)" when you actually want "Application (.exe)"

    So select "Application (.exe)", click OK to return to the main view.

    Now under the Build menu, click "clean", then "build"


  • Registered Users Posts: 2,066 ✭✭✭Finnbar01


    ressem wrote: »
    As CreepingDeath says...

    In Visual Studio, in the top menu, click
    "Project > Properties"

    This brings up the "Property pages" dialog.
    On the left menu panel click "Configuration Properties > General"

    The right panel should now contain a list of settings for
    "General" and "Project Defaults" properties.
    In the "Project Defaults" section the first entry should be the "Configuration Type" and you seem to have it set to "Dynamic Library(.dll)" when you actually want "Application (.exe)"

    So select "Application (.exe)", click OK to return to the main view.

    Now under the Build menu, click "clean", then "build"

    Thanks but I don't seem to have a build menu on my toolbar.


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    When you were creating the new project you selected the wrong option in the wizard, you picked dll instead of exe.

    Best to create a BLANK project, otherwise the microsoft specific stuff may confuse you. That means don't try to use precompiled header either (stdafx.h).

    You would be better off using linux and gcc to learn. Visual Studio is a complex tool and requires lots of learning itself, nevermind c++. Once you are comfortable with basic stuff then you could switch to visual studio (it is the best ide after all).


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Finnbar01 wrote: »
    Thanks but I don't seem to have a build menu on my toolbar.

    Sorry,
    I'm looking at the studio version.
    If you get that far you should just be able to build by hitting the execute button or debug menu.


  • Advertisement
  • Registered Users Posts: 2,066 ✭✭✭Finnbar01


    srsly78 wrote: »
    When you were creating the new project you selected the wrong option in the wizard, you picked dll instead of exe.

    Best to create a BLANK project, otherwise the microsoft specific stuff may confuse you. That means don't try to use precompiled header either (stdafx.h).

    You would be better off using linux and gcc to learn. Visual Studio is a complex tool and requires lots of learning itself, nevermind c++. Once you are comfortable with basic stuff then you could switch to visual studio (it is the best ide after all).

    Thanks everybody for your replies.

    I guess learning Visual Studio is a task in itself. I keep getting problems which I don't understand, so I'm way in over my head. I'll stick with C++ and try a different application.

    Could anyone tell me how I can get Linux or gcc?


  • Registered Users Posts: 2,020 ✭✭✭Colonel Panic


    The learning curve for using something like gcc and an OS like Linux is a bit higher than Visual Studio. You should stick with VS for now.


  • Registered Users Posts: 2,066 ✭✭✭Finnbar01


    The learning curve for using something like gcc and an OS like Linux is a bit higher than Visual Studio. You should stick with VS for now.


    Thanks.

    I tried to run/execute the program and I got this:
    'HelloWorld.exe': Loaded 'C:\Users\Documents\Visual Studio 2010\Projects\HelloWorld\Debug\HelloWorld.exe', Symbols loaded.
    'HelloWorld.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
    'HelloWorld.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
    'HelloWorld.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
    'HelloWorld.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
    The program '[6412] HelloWorld.exe: Native' has exited with code 0 (0x0).


    I didn't see 'Hello World' as I would have expected.


  • Registered Users Posts: 3,945 ✭✭✭Anima


    return 0;
    The program '[6412] HelloWorld.exe: Native' has exited with code 0 (0x0).

    That's because nothing is blocking execution and the program is exiting before you get a chance to see it.

    Usually people use std::cin or something like that so the user has to hit something before it exits. So add that before the return value.


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    OP that means it is working correctly. The problem is the console window will flash up with "hello world" and then disappear instantly because the program is finished. As above poster suggests you should put a "press any key to continue" in, this will make the window stay on the screen.


  • Advertisement
  • Registered Users Posts: 2,066 ✭✭✭Finnbar01


    That's great, I actually saw the window pop up for a split second.

    I understand what I need to do now.

    BTW, I'm going to treat this new learning experience ( :) ) as playing a video game. I'll start off pretty lousy but will improve over time the longer I play it.


Advertisement