0

When building with Visual C++, I noticed that a simple executable helloworld.exe (displaying a WinAPI MessageBox) can be shipped to any computer using Windows XP, Vista, 7, 8, 10, and will run without any third-party dll or redistribuable packages.

Now that I'm moving to CodeBlocks + GCC, will the same be true? i.e. will a simple executable displaying a WinAPI MessageBox be able to run on all Win XP, Vista, 7, 8, 10 without any other packages needed, specific to GCC ?

Basj
  • 41,386
  • 99
  • 383
  • 673
  • Future readers should note that by default, Visual C++ will produce an executable that requires redistributable packages. You can configure it to generate a stand-alone executable, of course, but it isn't the default behaviour. – Harry Johnston Jul 09 '17 at 03:01
  • @HarryJohnston Useful information indeed! Where is the setting to generate a stand-alone executable (which menu / submenu) in VC++? – Basj Jul 09 '17 at 13:22
  • For plain C it is the "Runtime Library" setting, under "Code Generation". I'm not sure about the STL. – Harry Johnston Jul 09 '17 at 21:58

3 Answers3

2

As with all programs, including those built with VS, guaranteeing the program will work across all those Windows versions is not trivial. But yes, you can generally write console applications with GCC that will work across them without any third-party DLLs - my own CSVfix application certainly does. And you can certainly use GCC to display a message box without such things. I would recommend using TDM GCC, a version of which comes with one of the Code::Blocks packages, as the most straightforward way of doing such a thing.

  • I used the default MinGW compiler [shipped with CodeBlocks](http://www.codeblocks.org/downloads/26) : codeblocks-16.01mingw-setup.exe. Usually, for command line applications or basic GUI app (using no GTK nor wxWidgets), are there no `mingw.dll`, `gcc.dll` or similar things to ship? – Basj Jul 08 '17 at 22:36
  • No, there are not. –  Jul 08 '17 at 22:38
0

A way I have used before to make sure everything was linked properly, is to statically link by passing the -static flag when compiling. in g++ that would be like this: g++ hello.cpp -o hello.exe -static. That should take care of it. This way you only need the binary without the libstdc++6.dll. So if you can pass linker flags in code::blocks do it.

Dimos
  • 33
  • 10
  • Thanks @Dimos. Where (which menu) can we set this in code::blocks ? – Basj Jul 09 '17 at 13:23
  • @Basj [like this](https://stackoverflow.com/questions/23049844/adding-linker-options-to-codeblocks) . I use Qt Creator so not sure how accurate/current this is. – Dimos Jul 09 '17 at 13:32
-1

I tried a bit more, and a .exe made with Code::blocks / GCC / MinGW does need an external file: libstdc++-6.dll.

There is probably a way to remove this dependency with a statically linked executable, as stated here, but some comments there show it's not as easy as it might seem.

Basj
  • 41,386
  • 99
  • 383
  • 673