Running a program?

I have built a program on calculating the area of a rectangle as the user inputs the length and width.

It works fine, however, my question is. If I want to send it to someone, what files from the whole folder do I need to send (.zip ). Also, how will they be able to run it, without a compiler.

I can easily run it from:

C:\Documents and Settings\Peter\My Documents\Visual Studio 2005\Projects\optut\debug however, as I've seen other programs, they usually have just a simple .exe file.

 

If it helps, here is the code:

 

using namespace std;

int main()

{

int length; // this declares a variable

int width; //this declares another variable

cout << "Enter the length: ";

cin >> length; // input the length (this inputs the value of length from the keyboard)

cout << "Enter the width: ";

cin >> width; // input the width

cout << "The area is " << length * width;

getch();

return 0;

}

Basically, it's a CLR application and only have one source file.

 

 



Answer this question

Running a program?

  • Yovav

    Search for the file on your machine. Then try running it.

    I can't help you without you providing more details.

    Note: The option is /MT and not /TM

    Thanks,
    Ayman Shoukry
    VC++ Team


  • RyanRos

    it is .exe file.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • lanfong

    Ok, well, I created another project as a win32 application. I am a beginner working with C++ so I wasn't sure.

    Along with the new project, came another stdafx.cpp file but I suppose I'll just ignore that for now.

    Would I still need to use the instructions from your blog regarding the DLL libraries deployment, or is there another more straightforward method


  • Martin Woodward

    Right, I specified /MT in the properties but now it the project won't sucessfully build. However, if I change it back to MDd, it works.

    I'm confused :(.


  • adidion

    When I "Build" > "Compile", it says it's succeded. Where would I be able to find this program though as it's not where it was before

     

    Also, when I "Debug" > "Start without debugging", I get over 30 errors and it fails if it's in this /TM mode. It works otherwise.

     


  • Osama Alborbar

    I am not sure why you are choosing a CLR application since your sample doesn't need to depend on the .Net Framework. You can just pick a win32 console application which removes dependency on the .Net Framework.

    Of course if you still need to use CLR applications then the person running it should have the .Net Framework installed on his/her machine.

    As for the rest of the files you need to distribute, it depends on how you are linking to the CRT. If you are linking dynamically (using the /MD compiler switch...you can see that from the build log) then you need the SxS binaries. In this case see http://blogs.msdn.com/aymans/archive/2006/04/04/568466.aspx that decribes the possbile options for deploying your application.

    If that is still not something necessary for such simple application, you can just link statically to the CRT using the /MT compiler option, in this case you don't need the SxS binaries.

    Hope this helps!

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Joachim Meyer

    I only find the .cpp and object file with the according name on my machine. What extension should this file that I'm looking for have

     

    Yes, sorry, it is /MT, my mistake.


  • Prunier

    I deleted the stdafx.cpp file that came default with the new win32 application and thus I get this error:

     

     

    Compiling...
    test.cpp
    c:\documents and settings\peter\my documents\visual studio 2005\projects\test\test\test.cpp(21) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source 
    
    However, if I create a new win32 project and leave it all as it is, just simply copying my code to "test1.cpp", I get these errors. And the program won't complete:
     
     

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

    1>Compiling...

    1>stdafx.cpp

    1>Compiling...

    1>test1.cpp

    1>c:\documents and settings\peter\my documents\visual studio 2005\projects\test1\test1\test1.cpp(22) : warning C4996: 'getch' was declared deprecated

    1> c:\program files\microsoft visual studio 8\vc\include\conio.h(145) : see declaration of 'getch'

    1> Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.'

    1>Linking...

    1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

    1>libcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW

    1>test1.obj : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "protected: virtual char const * __thiscall std::ctype<char>::_Do_widen_s(char const *,char const *,char *,unsigned int)const " ( _Do_widen_s@ $ctype@D@std@@MBEPBDPBD0PADI@Z)

    1>libcpmtd.lib(cin.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW

    1>libcpmtd.lib(cout.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW

    1>libcpmtd.lib(stdthrow.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW

    1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" ( 2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)

    1>libcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol __malloc_dbg

    1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" ( 3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)

    1>libcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol __free_dbg

    1>libcpmtd.lib(_tolower.obj) : error LNK2019: unresolved external symbol __calloc_dbg referenced in function __Getctype

    1>C:\Documents and Settings\Peter\My Documents\Visual Studio 2005\Projects\test1\Debug\test1.exe : fatal error LNK1120: 4 unresolved externals

    1>Build log was saved at "file://c:\Documents and Settings\Peter\My Documents\Visual Studio 2005\Projects\test1\test1\Debug\BuildLog.htm"

    1>test1 - 11 error(s), 2 warning(s)

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

     

     

     

     

    This is what I have under Solution Explorer:

     

    Would be grateful if you could help me.


  • Icanreadabook

    hello....to all

  • RMS rookie

    If you build with /MT then you don't need the info from my blog. Take a look at http://msdn2.microsoft.com/en-US/library/2kzt1wy3.aspx on how to specify /MT

    Thanks,
    Ayman Shoukry
    VC++ Team


  • richwu

    Could you try by creating an "Empty" win32 application and then add a .cpp file to it.
    The copy the below file into the new cpp file you added:

    #include <iostream>
    using namespace std;

    int main()

    {

    int length; // this declares a variable

    int width; //this declares another variable

    cout << "Enter the length: ";

    cin >> length; // input the length (this inputs the value of length from the keyboard)

    cout << "Enter the width: ";

    cin >> width; // input the width

    cout << "The area is " << length * width;

    //getch();

    return 0;

    }

    Then try compiling!

    Thanks,
    Ayman Shoukry
    VC++ Team



  • Eric Frick

    What is the error you are getting

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Running a program?