I have written a program using c++ in Visual Studio 2022 that I would like to build and send to somebody else to run on their computer. How do I go about doing this?
I've scoured the internet and I've found two answers. One is to go to the "build" tab at the top and click "publish", but my Visual Studio does not have the publish option. The other answer is that when I build the project in Visual Studio, it should be building a .exe in the Debug/Release folder. But my Visual Studio builds a .exe.recipe file, and I don't know how to use that.
Thank you in advance for your help.
I have written a program using c++ in Visual Studio 2022 that I would like to build and send to somebody else to run on their computer. How do I go about doing this?
I've scoured the internet and I've found two answers. One is to go to the "build" tab at the top and click "publish", but my Visual Studio does not have the publish option. The other answer is that when I build the project in Visual Studio, it should be building a .exe in the Debug/Release folder. But my Visual Studio builds a .exe.recipe file, and I don't know how to use that.
Thank you in advance for your help.
Share Improve this question asked Feb 2 at 3:39 Dat 1 channelsDat 1 channels 153 bronze badges 4- 1 The question is almost identical to the question “How to do programming?” The simple answer is: your C++ project, if it builds at all, always build some executable file. You need to learn where your files are, what are the dependencies, and how to control their locations. Basically, you build the entire solution and send all executable files, typically, all .exe and .dll files, dependencies. – Sergey A Kryukov Commented Feb 2 at 4:13
- Why are you not getting your executable files? There can be many reasons. You need to simplify your source files as much as possible and show us what you have: solution, project file(s), C++ source file(s). – Sergey A Kryukov Commented Feb 2 at 4:17
- 1 If you're able to run your program then the executable file is there somewhere, you're probably just looking in the wrong directory. When you find the exe that's all you need to run it in another computer. You might also need the msvc redistributeable learn.microsoft/en-us/cpp/windows/… – Alan Birtles Commented Feb 2 at 6:08
- The .exe.recipe is not the executable, but an internal file the build system uses when creating the program. Also, when distributing your program, it is always the Release build you use. The Debug version only runs on systems with Visual Studio installed. – BoP Commented Feb 2 at 9:53
2 Answers
Reset to default 0You are looking for the wrong output folder path.
.exe.recipe
file is in folder $(Project)/x64/DebugOrRelease
The default x64 exe output path is located in the x64 folder in the same directory as the sln file.
└───ConsoleApplication1(.sln)
├───ConsoleApplication1(.vcxproj)
│ └───x64
│ └───Release
│ └───.exe.recipe // wrong
└───x64
└───Release // right
You can click rebuild
and check the output commands from the output window in Visual Studio.
1>------ Build started: Project: ConsoleApplication1, Configuration: Release x64 ------
1>ConsoleApplication1.cpp
1>Generating code
.......
1>Finished generating code
1>ConsoleApplication1.vcxproj -> .....\ConsoleApplication1\x64\Release\ConsoleApplication1.exe
Note that you need to distribute the program built in release mode.
First, you need to switch from Debug to Release mode, which can greatly improve performance and reduce the size of the executable file. Run your program, open Task Manager, right click and select "Open File Location", then copy the exe file to the USB.
When you try to run this exe on another computer, you may encounter the following problems:
The program can't start because xxx.dll is missing from your computer. Try reinstalling the program to fix this problem.
There are three solutions: central deployment, local deployment, and static linking.
Central deployment puts the library files under the Windows directory, where all applications can access them automatically.
How: Install Microsoft Visual C++ Redistributable on the target computer. Notice that the VC++ redistributable does not install the debug libraries.
Local deployment puts the library files in the same directory as your application.
How to do it: Find the corresponding dll on your computer (usually located in C:\Windows\System32) and put it in the same folder as your exe.
Static linking binds the library code into your application. This will significantly increase the size of the exe file (for a small program, it is about from tens of KB to hundreds of KB)
How to do it: Open the Project Properties dialog and, in "Configuration Properties -> C/C++ -> Code Generation", field "Runtime Library", choose "Multi-threaded (/MT)".