Console Applications only work on computer with the IDE

I'm using a text book to learn C++ and am writing my first programs.

They compile fine and work the way I want them to, from Visual Studio or Windows Explorer.

However, if I move them to another computer (with a disk), they don't work. Something about the configuration of the application.

I've tried CLR console apps and Win 32 console apps (with header).

I move the entire project, not just the .exe

I would really like to be able to give other people my programs, please help me out!!

PLEASE!




Answer this question

Console Applications only work on computer with the IDE

  • Dexter Lo

    I don't think anyone has mentioned that you can also statically link to the runtime libraries. Check the /MT option (you can type this in the MSDN Library Viewer in the index. The page will have a description on how to enable it from within the IDE).

    With that option your executable will not rely on non-Windows DLLs.

    -hg


  • Qiuwei

    Ah ha!!

    I am using the debug build, where do I find the release build.

    Once I do find it, please tell me exactly what I have to move.



  • Jimmy Bergmark

    Yes, correct, however, static linking is only supported for unmanaged (non .NET) apps. Also, if there are any security updates you don't get to take advantage of them, so it's highly discouraged.
  • mp112849

    To be honest my take on this one is that it's just Microsoft's typical developer marketing ***. I guess, some one of the higher-ups was eventually fed up with everyone pointing at Microsoft with new vulnerabilities showing up every other week. Since then, there's some kind of paranoia about security. Just take a look at the "secure C/C++ library". I don't know any reputable C++ developer how'd say it's something she'd use in her own code.

    Anyway, chances are if there's something that Microsoft perceives as a security risk, I wouldn't bet that they cared too much about our programs being broken (remember XP SP2 )

    All that being said, there are good reason for dynamic linking and there are good reasons for static linking. However, they are IMHO not related to security.

    -hg


  • Alan_Williams

    I believe the answer you were given will solve your problem, if you're not using .NET. If you are, you also need to install the .NET framework 2.0. I just thought I'd also expand on what this all means.

    C++ is quite an old language now, certainly compared to C#. When your application is built, some libraries that you use may not be included in your exe, they are in dlls that your exe knows how to load. CRT stands for the C run time. C is the language that C++ is built on. MFC stands for the Microsoft Foundation Classes, a library for building windows programs, but I would guess you're using the express edition, which would mean you don't have it.

    Microsoft has added to the mix with .NET, a new framework that has support in C++, and which the Express edition favours. If you use it, your app will be slower, and less portable ( although MFC is also not portable ). Also, it means you need to install the .NET framework for your app to run.



  • Elie Rodrigue

    Try distributing the Release build (you may be giving your friend the debug build).

  • falconin

    Firstly, what version of Visual C++ 2005 are you using Express or Professional Edition   For Win32 Console Apps make sure you build a Release version not a debug version and then follow the instructions below:

    If Express, use the instructions at the following post marked as an answer at:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=164880&SiteID=1

    If Professional, then run the following executable on the machine you want to run your app on (copy it from your machine to the other machine):

    \Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe

    Ted.


  • hyffrank

    You may need to give people the .NET framework ( for CLR apps ), and you almost certainly need to deploy the versions of the CRT and possibly MFC that you link against.

  • fulano2040

    Okay, to answer yourquestion, I'm using express.

    My problem might be that I'm not using any instillation programs or anything like that. The only thing I'm used to writing is the main cpp file.

    To show you what I mean, here is my most complicated code (also the one I'm trying to move):

    // Orc vs Human.cpp : Defines the entry point for the console application.

    #include "stdafx.h"
    #include <iostream>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;

    int s;
    void battle (bool w, int *php, int *pmhp);
    int rand_0toN1(int n);

    int main(){
    int hp = 3, mhp = 2;
    bool f, w, e, pg;

    cout << "If you pick a number other than 0 or 1 or" << endl;
    cout << "if you pick a letter, its you're problem." << endl << endl;

    while(1){
    cout << "You health is " << hp << "." << endl;
    cout << "You score is " << s << "." << endl;
    if (hp == 0){
    cout << "You're dead." << endl;
    cout << "Play (or try, failures) again, Yes(1) or No(0) ";
    cin >> pg;
    if(pg){
    hp = 3;
    s = 0;
    continue;
    }
    else
    break;
    }
    if (mhp == 0){
    cout << "Orc is dead." << endl;
    s++;
    cout << "You score is " << s << "." << endl;
    cout << "Keep fighting, Yes(1) or No(0) ";
    cin >> pg;
    if(pg){
    mhp = 2;
    continue;
    }
    else
    break;
    }
    cout << "There is an orc! Will you fight it(0) or run(1) ";
    cin >> f;
    if (f){
    cout << "You make it home safely." << endl;
    break;
    }
    cout << "Will you use the two-handed sword(0) or short sword and shield(1) ";
    cin >> w;
    battle(w, &hp, &mhp);
    }

    while(1){
    cout << "Will you exit, yes(1) or no(0) ";
    cin >> e;
    if(e)
    break;
    else
    cout << "Yes you will, its to late for any other choice! " << endl;
    }

    return 0;
    }

    void battle(bool w, int *php, int *pmhp){
    bool ph, mh;
    int phit, mhit;

    srand(time(NULL));

    phit = rand_0toN1(3);
    mhit = rand_0toN1(3);

    if(w){
    if(phit>1){
    cout << "You hit." << endl;
    ph = 1;
    *pmhp -= 1;
    }
    else{
    cout << "You miss." << endl;
    ph = 0;
    }
    }
    else{
    if(phit>0){
    cout << "You hit." << endl;
    ph = 1;
    *pmhp -= 1;
    }
    else{
    cout << "You miss." << endl;
    ph = 0;
    }
    }

    if(w){
    if(mhit>1){
    cout << "You're hit." << endl;
    mh = 1;
    *php -= 1;
    }
    else{
    cout << "His attack missed." << endl;
    mh = 1;
    }
    }
    else{
    if(mhit>0){
    cout << "You're hit." << endl;
    mh = 1;
    *php -= 1;
    }
    else{
    cout << "His attack missed." << endl;
    mh = 0;
    }
    }
    }


    int rand_0toN1(int n){
    return rand() % n;
    }


    The only other files I have are the precompiled header and the manifest thing (which seemed to have compiled succesfully).



  • eastlands

    Thank you all, static linking worked.

    Thank you for your concerns about my program's security, but I figure that by the time my programs are important enough to protect from hacking, I'll be able to protect them myself. Obviously I'm not copyrighting it, I just posted my code in public.

    Thank you again.



  • Deki PA

    math.h, stdlib.h and time.h are all part of the C runtime.  Therefore, you need to do what the other poster said, and follow the instructions on the correct marked answer on the post he linked to.

     Oh - and make sure it's a release build, the debug builds link to different dlls, which you should not distribute.



  • sps12

    Sorry, I don't know how to do that.

    First of all i'm not sure if I'm not sure if I'm using a .NET Framework, or even what t is.

    The acronyms CRT and MFC don't mean anything to me.

    Please Clarify in Layman's terms.



  • Leketje

    On the toolbar you should see a dropdown combo box with the word "Debug" in it. Just change that to "Release" and rebuild.
  • Console Applications only work on computer with the IDE