Click here to Skip to main content
12,623,850 members (29,081 online)
Click here to Skip to main content
Add your own
alternative version

Stats

27.4K views
330 downloads
27 bookmarked
Posted

Visual C++: How to Create Standalone Win32 Application Not Requiring Visual C++ Runtime

, 9 Dec 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to statically link a Win32 Project with Visual C++ libraries (m***.dll)

The Problem

You may think that your Win32 project created in Visual C++ without MFC, does not require on target machine anything other than native WinAPI dlls.

But it's wrong!!!

You will see it if you will try to run the project, the creation of the Visual C++ 2010, on a freshly installed Windows:

If you will open your EXE in DependencyWalker, you will see it requires one or few DLLs but Win32 DLLs (user32, kernel32, etc)!

What can we do to make the project standalone?

  1. We can put all of the required DLLs to folder with EXE or to C:\Windows\system32\ path.
  2. We can install onto target machine a Visual C++ Redistributable with the same version as your Visual Studio and with the same bit count (x86 or x64) as your EXE.
  3. We can statically link these DLLs into your EXE - and get 100% standalone executable!

Remark: Information bellow applies to VC++ 2008 Express, but must work In other versions, too.

Statically Linking - Way 1

  1. First, go to Project -> Properties menu.
  2. Go to Configuration Properties -> C/C++ -> Code Generation.
  3. Set Runtime library property to Multi-threaded (/MT) or Multi-threaded Debug (/MTd).
  4. Build and debug it!

Statically Linking - Way 2

  1. First, go to Project -> Properties menu.
  2. Go to Configuration Properties -> Linker -> Command Line. Copy all lib names to the clipboard:

  3. Go to Configuration Properties -> General. Set Use of MFC property to Use MFC in a Static Library.
  4. Go back to linker command line.

    You will not see these libs in linker command line! It's wrong because these DLLs are needed to run your app if it uses Win32 API. To correct it, add them to Additional options:

  5. Build and debug it!

Result

Now your EXE weighs a few hundred KBs more than before, but, it is fully standalone!

CLR (.NET)

Unfortunately, you can use static linking only for VC++ Redist and other unmanaged libs, but can't do it with managed libs, can't create CLR project not requiring .NET. Because .NET isn't just library kit, it's also interpreter-like compiler that runs your application and runs standard .NET DLLs (system.dll, etc.), it's needed to be installed on PC.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Comments and Discussions

 
QuestionIt worked, thank you Pin
José Roberto Araújo Júnior9-Jul-16 11:50
memberJosé Roberto Araújo Júnior9-Jul-16 11:50 
GeneralMy vote of 1 Pin
Bartlomiej Filipek12-Dec-14 2:55
memberBartlomiej Filipek12-Dec-14 2:55 
GeneralRe: My vote of 1 Pin
Emiliarge12-Dec-14 3:59
professionalEmiliarge12-Dec-14 3:59 
GeneralMy vote of 1 Pin
Ben Ratzlaff11-Dec-14 11:19
memberBen Ratzlaff11-Dec-14 11:19 
GeneralRe: My vote of 1 Pin
Jamming111-Dec-14 11:43
memberJamming111-Dec-14 11:43 
GeneralMy vote of 1 Pin
Jamming110-Dec-14 7:18
memberJamming110-Dec-14 7:18 
QuestionIt's simple, why complicate things!!! Pin
Jamming110-Dec-14 5:53
memberJamming110-Dec-14 5:53 
AnswerRe: It's simple, why complicate things!!! Pin
Emiliarge10-Dec-14 14:02
professionalEmiliarge10-Dec-14 14:02 
GeneralRe: It's simple, why complicate things!!! Pin
David A. Gray12-Dec-14 18:11
memberDavid A. Gray12-Dec-14 18:11 
QuestionOther / preferred(?) way Pin
_GyB_10-Dec-14 4:19
member_GyB_10-Dec-14 4:19 
QuestionNow your EXE weighs a few hundred KBs more than before Pin
Kochise10-Dec-14 3:54
memberKochise10-Dec-14 3:54 
AnswerRe: Now your EXE weighs a few hundred KBs more than before Pin
Emiliarge10-Dec-14 4:52
memberEmiliarge10-Dec-14 4:52 
GeneralRe: Now your EXE weighs a few hundred KBs more than before Pin
Kochise29-Dec-14 2:33
memberKochise29-Dec-14 2:33 
GeneralRe: Now your EXE weighs a few hundred KBs more than before Pin
Emiliarge29-Dec-14 6:59
professionalEmiliarge29-Dec-14 6:59 
GeneralRe: Now your EXE weighs a few hundred KBs more than before Pin
Kochise16-Jan-15 3:09
memberKochise16-Jan-15 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 10 Dec 2014
Article Copyright 2014 by Emiliarge
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid