3

I wrote the following program in Codeblocks

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c;
    a = 5;
    b = 6;
    c = a+b;
    printf("Hello world!\n");
    return 0;
}  

for both debug and release builds. The exe files are created in the respective bin\debug and bin\release folders, and the program works fine when run from codeblocks.

However when I try to execute the exe files form bin\debug or bin\release, I get the libgcc_s_dw2-1.dll is missing from your computer. error.

Searching for libgcc_s_dw2-1.dll only brings out other posts that ask how to fix this problem, where the suggested solution is to either add the path to libgcc_s_dw2-1.dll, which is somewhere inside inthe MinGW installation, to the system path, or statically link the dll file to the program during compilation.

My question is, why is this necessary? This is a very simple hello world program. The file is in a codeblocks project and file extension is .c (main.c, so I'm guessing gcc is automatically invoking the C compiler and it doesn't have anything to do with compiling C code with cpp compiler?) and the compiler settings have been left at their default values after a fresh MinGW and Codeblocks install. Since this program is very simple I am assuming it should work the same way in any other older version compilers as well.

Then what is the use of this dll file? What is happening under the hood when compiling this program? Suppose I compile the hello world program above and distribute the exe file to my friends. How am I supposed to know that I should have statically linked the dll file during compile?

user13267
  • 6,871
  • 28
  • 80
  • 138

0 Answers0