C++ Compiling question.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    C++ Compiling question.

    Hi.

    I'm trying to create a .exe file that I can execute on any windows xp/2k computer.

    Im used to writing in C# so I thought I'd try this in C++.
    To test this I wrote a simple hello world app in Visual Studio and compiled using the same method I would using C# and it created a .exe file.
    This exe file runs perfectly on my machine but wont run on any other computer.

    This is my test code.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "Hello World!" << endl;
    	return 0;
    }
    I've searched the net for instructions on how to compile C++ and with what little info I've found I thought once I had the exe file it shoud work.

    What am I missing here?

    Thanks in advance.
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by Atli
    Hi.

    I'm trying to create a .exe file that I can execute on any windows xp/2k computer.

    Im used to writing in C# so I thought I'd try this in C++.
    To test this I wrote a simple hello world app in Visual Studio and compiled using the same method I would using C# and it created a .exe file.
    This exe file runs perfectly on my machine but wont run on any other computer.

    This is my test code.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "Hello World!" << endl;
    	return 0;
    }
    I've searched the net for instructions on how to compile C++ and with what little info I've found I thought once I had the exe file it shoud work.

    What am I missing here?

    Thanks in advance.
    Did you copied just .exe on other computer or have you copied all other files
    that compiler makes?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      The compiler made 2 files, .exe and .pdb.
      I copied them both (eventually) and ran the exe file without any luck.
      It gives me an error saying "This application has failed to start becuase the application configuration is incorrect. Reinstalling the application may fix this problem."

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by Atli
        The compiler made 2 files, .exe and .pdb.
        I copied them both (eventually) and ran the exe file without any luck.
        It gives me an error saying "This application has failed to start becuase the application configuration is incorrect. Reinstalling the application may fix this problem."
        You should only need to copy the exe.

        What is actually happening is you are linking to the C runtime dynamically (in VC++ 2005?) and the target machine does not have the correct C runtime assembly installed.

        Microsoft have changed the way they link to their dynamic libraries so this error no longer shows up as a missing library.

        You have 2 options to fix this problem

        1. Install the correct run time assembly on every machine you wish to copy your program to information here.

        2. Change your project so instead of linking dynamically you are linking statically. This will put all the code the program requires in the executable. Do this by going to Project -> Properties (Alt-F7) in the tree select Configuration Properties -> C/C++ -> Code Generation. In the right hand pane change run time library from Multi-Threaded Debug DLL -> Multi-Threaded Debug for the debug configuration and Multi-Threaded DLL -> Multi-Threaded for the release configuration.

        Comment

        • Savage
          Recognized Expert Top Contributor
          • Feb 2007
          • 1759

          #5
          Originally posted by Atli
          The compiler made 2 files, .exe and .pdb.
          I copied them both (eventually) and ran the exe file without any luck.
          It gives me an error saying "This application has failed to start becuase the application configuration is incorrect. Reinstalling the application may fix this problem."
          There are only two files?

          I have four files:

          *.exe,*.obj,*.r es,*tds

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Thank you Banfa.
            Your second suggestion was a perfect solution. (Using VS 2005)

            I guess they changed this so C++ could use the .Net libraries, which probbly means that C++ apps that use .Net can not be compiled using this method.

            O and Savage, there were two debug/release folder, one of them had like 10 different files, including all 4 you mentioned but without the exe file. The one I used was in the parent dir of the larger one.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Originally posted by Savage
              There are only two files?

              I have four files:

              *.exe,*.obj,*.r es,*tds
              Yes but the *.exe is the output, the *.obj and *.res are intermediate files (output by compiler and resource compiler as input to the linker) and the *.tds is symbol information for use when you run the program using the symbolic debugger (you are using Borland right?).

              The *.exe is the only one that needs to be distributed.

              Comment

              Working...