1

I wrote some programms in C++. I can run it on my Computer. But if I try to open the .exe file on other pcs there is always an error because of an missing DLL. If the programms is very short, there is no Error. I dont understand why!

Takeo12
  • 29
  • 1
  • 2
  • 2
    Your computer doesn't need them? Are you sure about that? Perhaps it's just not complaining because your computer actually has those files. What DLLs are we talking about, anyway? – Blaze Feb 22 '19 at 15:13
  • Probably because you have the compiler installed and the other machine does not have the compiler installed or has a different version. The compiler ships with dlls that are in one of the folders in your `PATH` environment variable. These are automatically searched when a dll is not found in the same folder as the executable. – drescherjm Feb 22 '19 at 15:14
  • Which DLLs? If you have an `FOO.EXE` or `BAR.DLL` you can use `DEPENDS.EXE` to see its DLL dependencies. – Eljay Feb 22 '19 at 15:15
  • As other people mentioned, most likely you are depending on the C Runtime. In Visual Studio you have the /MT flag that allows you to embed the C Runtime in your binary (static linking). I'm not sure if that flag is also available for MinGW. This [post](https://stackoverflow.com/questions/757418/should-i-compile-with-md-or-mt) might shed some light. – Claudiu Guiman Feb 22 '19 at 15:45

1 Answers1

4

Your compiler came with the DLLs often.

Simple operations, like printing and in some cases calling your application's entry point (ie, something like main), are done by libraries and are not always provided by the OS. On windows, you are supposed to ship with a "redistributable" C++ runtime.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
  • And what should I do? I used and . I tested the file on 2 different PCs and the Missing DLL was different(gxx_personality_v0 and libgcc_s_dw2.1) – Takeo12 Feb 22 '19 at 16:07
  • @TakeoTakeshii See http://www.mingw.org/wiki/mingw/ -- "mingw-runtime: Header files and import libraries for the default C runtime library, (also known as msvcrt), which is required by MinGW compiled programs running on the Microsoft Windows operating system. You must install this package, together with gcc-core, to obtain a correctly functioning compiler suite." -- it looks like MinGW uses msvcrt redistributables. Which version you need to install will depend on your exact MinGW version. Question did not ask "what do I need to do to get this to work", it merely asked "why is it broken?" – Yakk - Adam Nevraumont Feb 22 '19 at 16:14
  • 1
    @TakeoTakeshii I can answer "why is it broken", but I am no expert on mingw to know how to get the right redistributable package etc. Please ask a new question. In it, include as much version information about the mingw you have, a [mcve] that shows the problem, and a quoted text copy of the error messages. Someone with mingw experience can probably tell you what redistributable package you need. – Yakk - Adam Nevraumont Feb 22 '19 at 16:16
  • 1
    @TakeoTakeshii "And what should I do?" - You should distribute the required DLLs along with your application. This is commonly done by having your installer include the Visual Studio redistributable installer and running that as part of your application installation. But you can also just bundle the files needed in your installer and drop them into the same directory your application is installed into. – Jesper Juhl Feb 22 '19 at 16:34
  • @JesperJuhl And sometimes you can "statically link" the required libraries. – Yakk - Adam Nevraumont Feb 22 '19 at 16:36