Building Independent Executable File in Visual Studio

Because of .dll dependency, project in default Visual Studio setup cannot build an independent executable file ( of cause if you program is as tiny as a “Hello world”, it might works). In order to build an independent executable file, you need to eliminate those .dll dependency. Here will show how to do it in Visual Studio 2010. It should be similar in VS 2012:

In Solution Explorer, right click the project you want to build independent .exe, go to Properties->Configuration Properties->C/C++->Code Generation->Runtime Library. Set the value without DLL.

Be aware if your project is also depended on other project(s) or 3rd party .lib. Those projects should also do the above setting, as well as those 3rd party .lib should also build under the above setup. Otherwise, you will get whole bunch of LNK 2005 linking error.

Also once your independent .exe can run within Visual Studio, make sure the working directory also correct for the .exe file. For example, if your program need an image file under the project directory, in your release build, there may not be such file under the release folder. In this case you run .exe simply double click, it may not run as you expected because of the lack of the image file.

Leave a Reply

Your email address will not be published. Required fields are marked *