How to convert MVS C++ code into executable application? - c++

So I've made a small program in Microsoft Visual Studio C++ (2008 edition) and I want to convert it to .exe format.
I know that I can find the .exe in my project directory, however it only runs fine on my own PC. When I send it over to someone else (who doesn't have Visual Studio installed or anything), it doesn't run.
I've read a little about this and it seems to be about "linking". Now I don't know anything about linking and I'm not eager to learn in depth about it right now...
I just want to make my incredibly simple program (which edits and creates text files) to run in .exe program on any computer. Is this possible, and if so - how?
Could you please guide me through the steps? I'm quite new to programming so I really need help on this one.
Thank you in advance...

The file you sent already is an exe file, but it is most likely a debug version of the program. Also, you need to see if you are linking against other DLLs, and if you are, you should distribute those with the program as well.
Since you have a simple program, it is most likely you have no other DLL dependencies, so try compiling in release mode as a first step. There will be a dropdown at the top of VS with Debug and Release, and Debug is currently selected.

You already have the .exe file that is created by linking all the .obj files that are compiled from the .cpp files you created. To repeat myself, the linking is already happening behind the scenes. However, there are two other issues. First, you may have compiled it in debug mode. In order to run your program on another Windows machine, it is best to compile it in release mode. Also, if your program uses DLLs, such as for MFC classes, then you need to copy those DLLs to the other computer as well. In order to do this correctly, you should look at creating a setup.exe file which will correctly install your program and all the required DLLs. There are tools that can help you do this, such as InstallShield.

I think you should install runtime components of Visual C++ Libraries : "Microsoft Visual C++ 2008 Redistributable Package (x86)" required to run applications developed with Visual C++ on a computer that does not have Visual C++ 2008 installed.
http://www.microsoft.com/en-us/download/details.aspx?id=29

Related

Visual Studio 2017 C++ Exe for any pc (linking vcruntime140.dll)

I'm very new to GUI programming in c++, thus I don't have that much experience.
I created myself a GUI for my programm using the Visual Studio 2017 CRL package and now I'm trying to make this exe available for everyone.
The application works fine for those who have Visual Studio or VC Runtime installed but for those who don't the programm throws something like: "vcruntime140.dll is missing on your computer to run this app".
I am not sure how to link these dll's in my programm so that EVERYONE is able to use it.
I'm also not quit sure how I would link dll's.
There's basically two options.
The Standard in the industry is to ship the Visual Studio 20xx Runtime Redistributable Installer alongside your program, and have it run before anyone tries to run your program themselves, to make sure that the .dll files are installed onto the target computer.
The other option is to change the way that the libraries are linked to the executable at compile-time. This is done with a flag in Visual Studio:
Basically, you want to change the Runtime Library field to either say Multi-Threaded or Multi-Threaded Debug depending on whether you're in Release or Debug mode, as opposed to "Multi-Threaded DLL", which is the default.
Note, however, that you need to make sure that every single library you're using was compiled the same way: if any of them were compiled using the DLL version of the Runtime Library, they'll interoperate with your code in funny ways, and the least of your problems will be that they'll need the DLLs installed anyways, defeating your effort.
Naturally, that's not an issue if all your libraries are Header-Only, but if any of them have been compiled, then you'll need to recompile them using the correct settings.
You need to install Visual Studio 2017 redistribuables on the machine (that's how it works for every version of Visual Studio).
However, I could not find any official link on Microsoft website (probably because this is not officially released yet)....
You probably need to use 2015 version (for which redistribuables are available here) and wait for 2017 to become an official release.

Release not working on different PC

I am not so experienced with C++ and MS Visual Studio. I am currently having issue with releasing .exe and trying to run the program on different PC. In the program I'm using additional library (magick++). I've configured the Runtime Library in Visual Studio 2015 to Multi-threaded (/MT). I suppose, that with this configuration the .exe file should be running on different PCs, but when I try to run it, message with "CORE_RL_Magick++. dll is missing on this computer appears. Any idea, what might be wrong?
My second question is, if I would like to make a release with dynamic library /MD, how can I get the library to run it on different PC? Or do I have to install the library first (I mean if I have to install Imagemagick to the computer or is there some way I can get the nescessary library from the build in Visual Studio).
Thanks for every information.
Do you have CORE_RL_Magick++. dll in the path (including the directory that your exe program is running) somewhere on the computer that is failing.
The /MD and /MT commands effect what runtime is used, not what other libraries the program is dependant on.
So with /MT, it will compile a static version of the visual c libs into the exe, but if linked against the magic dll, it will still need that CORE_RL_Magick++. dll in order to run.
I think /MD is a better choice, for smaller size.
If you want to run program on other PC, you may need to install Visual Studio Redistributable (could be downloaded on Microsoft website) on the PC first.
Agree with Martin Zhai. I had this problem when attempting to run my program on another machine after upgrading to 2015. The DLL I wanted to use would not be found despite being local. Installing Visual C++ Redistributable for Visual Studio 2015 fixed this.

Create a self-contained program in C++

I'm using Visual Studio 2012. I wish to create a completely self-contained program that can be used on a machine without visual studio installed just by copying the exe file directly. I used to need to first run visual c++ 2012 redistributable to make the program work. Is there any way to make everything run in one exe? I would not like to use an installer either as it is a fairly simple program; the time it takes for the user to use the installer will probably be more than my program...
So is there any way to statically link everything? Right now, it just crashes when run on a new machine, but once I install VS2012 express on that machine, it suddenly starts to work.
Any help would be appreciated.
To get static linking in an MFC project set the project properties (for the release build) as follows:
C/C++ Code Generation, Runtime Library: Multi-threaded (/MT)
Configuration Properties, General: Use of MFC: Use MFC is a Static Library
A simple exe with these properties will run standalone.
Useful information found here http://msdn.microsoft.com/en-us/library/aa235516(v=vs.60).aspx
and here http://msdn.microsoft.com/en-us/library/f22wcbea.aspx
Once you run your program, you can find it's executable in the Debug\ folder of your project.
Hope it helps!
Sarge

MSVCR100D.dll error at runtime

Ok , so i created a program using VC++ 2010. it ran just fine.
Got to work and could only install vc++ 8 due to having a crappy computer that is still stuck on xp sp2...
Everything will link up and build with no errors, But when the program starts to run i get "This application has failed to start because MSVCR100D.dll was not found"
I tried changing the runtime libary from MDd to MTd but still no luck...any idea?
That DLL comes with Visual Studio 2010. If you want to use your program, you'll somehow have to get your hands on it. If possible at your work, you can download it. Another (probably better) option would be to take it with you from home on a USB drive.
Edit: You can also try re-creating the project, and then copying the source code over into the new project. Your newly created project (in Visual Studio 2008) should not be depending on that erroneous DLL.
Edit 2: As Hans Passant added in a comment, this DLL is needed by Debug compilations of your program. So if you simply compile as Release, you can safely ignore the first part of my post. (I hope I'm not breaking gentleman rules by adding this to my post.)
MSVCR100D.dll is for debug mode, and is installed with visual studio 2010, since 2008 has MSVCR80D. You can just google that and download it, and put it in the same direcrory, or just complie in release mode.
here is a download link. You need the small download zip file button, not the big ones.
http://www.dll-files.com/dllindex/dll-files.shtml?msvcr100d
As I know, MSVCR100D is debug version of runtime library used by VC2010。So, if your point either is:
(1) you do not have that dll which you really need, you can download at http://www.dll-files.com/dllindex/dll-files.shtml?msvcr100d or
(2) you want to run that program without requirement of MSVCR100/D.dll, you may need to recreate a project in VC8, then substitute with your source files (not solution file or other files managed by Vistual Studio).
FYI: If my memory were not going wrong, I remember that a project created by higher version of VS cannot be opened directly by lower version one. So, how did you build them?

Running .exe crashes while running from vs2010 is successful

I've developed a c++ program using Visual Studio 2010 and it works perfectly, but while trying to start it with the .exe file created in the debug folder instead of inside the VS2010, it crashes. It updates my DB once, but then it crashes unexpectly..
Does anyone know why? What should I do to avoid it in order to be able to run my application in another PC. It uses the winsock library and mysql API for C, so I'm wondering if I need to configure something else that the VS2010 doesn't do by its own while linking or so.
Did you depend on the current directory? We had a case once that turned up where that was the problem.
You should set the build configuration to Release, and use the .exe from the Release folder, once you rebuild the application. The executable from the Debug folder is (in principle) only used by Visual Studio internally, and it would therefore make no sense to redistribute it.
Note however, that in order to run any application created with visual C++, the user must install the visual C++ redistributable package, so make sure that the user has got that installed.