Create standalone (indipendent) exe

Hi,
i wish to understand what code habit i should take in order to develop indipendent application (i want to be able to just give the exe,without any other dependencies).
For example,I think that i have to use Static Library,and not rely on windows api,right? What other things should i consider?
I'm not sure what your question is. If you want a program that works on all platforms all you have to do is use standard c++ code. What is the actual problem here?
I think he wants to make an exe which would be working on it's own - in visual studio you have to install packages or give dll files manually to your client, without that you will have "dll missing" message box.
Exactly as TheHardew said. I want that the users that download the program don't have to download anything else than the exe.
if you are only using standard c++ and windows libraries, it will be ok. If you use any 3rd party libraries make sure you can link them statically.
Yes,but also something as:
1
2
3
4
5
6
7
8
9
#include <iostream>

int main ()
{

    std::cout << "aaaaaa" <<std::endl;
    std::cin.get();
    return 0;
}

don't run on a fresh windows install because some dll are not found. I need my program to run in a minimal windows enviroment. Something as a just formatted windows.
If you're using visual studio then as TheHardew says, that's probably why. If you compile that with codeblocks, then it can be run on any windows environment.
I compiled it with Code::blocks and the result is the same. If i take the exe and try to run it in a fresh windows installation it won't run because "[...] xxxx missing ".
Last edited on
What does it say is missing exactly?
It says that libgcc_s_dw2-1.dll is missing. Maybe i'm compiling with the wrong option on codeblocks? :\
I use gcc as the compiler for codeblocks.
Last edited on
Check if it works: http://www.codeproject.com/Tips/851725/Visual-Cplusplus-How-to-Create-Standalone-Win-Appl
It's for visual studio, I think you use it.
BTW: You can check what your app requires with Dependency Walker: http://www.dependencywalker.com/
Last edited on
Try these gcc flags:
-static-libgcc -static-libstdc++

and add this to libs:
-static -lpthread
@joe7 Will it work with winapi?
It should work ok. The Win32 DLL's are part of the Windows installation and are always available. We are just trying to statically link GCC stuff to avoid dependencies.



Yeah! Linking statically in code::blocks worked fine! The only disadvantage is that the size of the exe increase dramatically when there are a lot of dependencies....to avoid this can i use the winapi dll (that are always avaible),loading them dynamically and use the windows api function instead of the standard c++ library ?
Executable size is one of the tradeoffs of static linking, is this really a problem though? How big was it?
I really believe all the MinGW GCC releases link statically. I have specifically tested all my code going back for a lot of years produced even by the earliest MinGW releases, and I have never found an exe that wouldn't run 'standalone' on bare bones systems, i.e., OEM only installs, with no development products installed on the machine. If I'm wrong about this, I wish someone here would point out my error, because this issue is important to me also.

Now with Visual Studio one must be careful to link with the /MT option, or for sure you'll need to include runtimes with the exe.

In terms of program sizes, any inclusion of anything from the C++ Standard Library, particularly iostream or string, is going to cause tremendous code bloat. These are simply large amounts of library code. iostream is much easier to eliminate than string. In my case I never use iostream, and I have my own String Class which saves me quite a bit as compared to the C+ Standard Library's String Class. I realize this is a very idyosyncratic thing to do on my part and is not for most C++ coders.

The Mingw g++ versions from around 2008 or so produced tight code. I'm talking versions around 4.4 or so. The newer 4.7, 4.8, nd 4.9 versions really produce extreme bloat due to inclusion of C11 compatibility and pthreads.
Did you use "release" mode? In my app I used only winapi, in release mode dynamic linking app has 41.5 kb and static linking app has 104 kb.
Topic archived. No new replies allowed.