6

I have read these two SO questions: Which runtime libraries to ship? and License of runtime libraries included in GCC? - both were very helpful but not quite what I was looking for.

I have always just written programs for use on my own machine, which has never caused me any problems, but now I want to start running software on other machines and I'm wary of the runtime requirements.

EDIT: See below example instead, this was misleading.

Specifically, if I write a C++ program on a Windows machine, compiled with gcc through MinGW, and want to run it on another machine:

  • Do I have to send the libstdc++.dll with my program?
  • Is this single file (I assume placed in the executable's directory) sufficient to allow the program to run?

Also, an identical example, except this time it is an Objective-C program. Is sending the libobjc.dll file to the other machine sufficient to allow the program to execute properly?

I am used to running programs on machines which have developer tools, etc, installed, but now I'm looking to run them on general purpose machines (friends', colleagues' etc), and I'm not quite sure what to do!


EDIT: In response to edifice's answer, I feel I should clarify what it is I'm looking for. I know how to identify the necessary DLL(s) (/dylibs, etc) that my programs use, (although I am accustomed to doing that work manually; I had not heard of any of the tools). My question was more "What do I do now?"

A more general example is probably needed:

Let's say I have written a program which has object files derived from C++, C and/or Objective-C(2) code. I have used some Windows API code which compiled successfully using MinGW's gcc. I also have a custom DLL I wrote in Visual Studio (C++).

I have identified which DLL's my program will use at runtime (one of which may be GCC's libobjc.dll, I'm not sure if this would/should make a difference on a Windows machine, but I want to make this as general as possible) - The "prerequisite DLLs".

I would like to run it on my colleagues' computers, most of which run Windows 7, but some now run Windows 8. Starting at the very start for the sake of completeness:

  • Do I need to transfer the prerequisite DLLs to my colleagues' computers?
  • What directory should I place them in? (exe directory / a system directory?)
  • Once in place, will the presence of these DLLs allow the program to execute correctly? (Assuming it knows where to find them)
  • Are there any other files that should be transferred with the DLLs?

Basically I'm trying to determine the entire thought-process for developing and running an application on another machine in terms of system runtime requirements.

Community
  • 1
  • 1
Ephemera
  • 8,672
  • 8
  • 44
  • 84

2 Answers2

5

When loading DLLs, the first place Windows looks is the directory that the exe is in. So it will probably work just fine to put the DLLs there.

For the Microsoft DLLs though, I think it makes more sense to ask your colleague to install the Visual C++ runtime, which is a redistributable package from Microsoft. Ideally you would make an installer using something like WiX and it would install that prerequisite for you, but it is OK to just tell your colleague to do it.

Be sure to include a license file with your software if you include DLLs from gcc, because the GPL requires it.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
3

libstdc++ isn't necessarily sufficient. You almost certainly need libgcc too, but actual dependencies are liable to vary with your particular application.

The best way to determine what you need to ship with your application is to load your EXE into a program like Dependency Walker.

Just as an example, I've compiled a test C++ program which simply prints a std::string. As you can see, it depends directly on two modules other than those that come with Windows; libgcc_s_dw2-1.dll in addition to libstdc++-6.dll.

You should remember to expand the tree under each DLL to make sure that it itself doesn't have any other dependencies (if A depends on B, B might depend on C even if A doesn't directly depend on C).

If you're worried and want the strongest assurances, you could install Windows into a virtual machine (VirtualBox is free) and test your application inside it. If you use Microsoft APIs, you may wish to check the MSDN documentation to see with what version of Windows they were introduced and ensure that it aligns with your target minimum Windows version.

Update: As xtofl points out this won't cover libraries loaded dynamically using LoadLibrary. If you want to cover this base, use Process Monitor to examine what DLL files are touched when you run the application. (Add an 'Image Path' criterion with the path to your EXE in order not to get flooded.) This has the added advantage that it covers all files, registry entries, etc. that your application depends on, not just DLLs.

edifice
  • 155
  • 7
  • `depends` will yield the binaries that are statically loaded. Dlls loaded with e.g. `LoadLibrary(...)` will be missed, but these are at your control anyway – xtofl Dec 27 '12 at 07:53
  • 1
    The best way is not to use depends. The best way is to understand your apps dependencies from the ground up. Reading the compiler documentation is going to be needed. – David Heffernan Dec 27 '12 at 08:18
  • You can also run your application from within Dependency Walker (Profile->Start Profiling). It will then update the view with those libraries that are actually loaded at runtime. – Johannes S. Dec 27 '12 at 11:09
  • @JohannesS. Which tells you about the dependencies on one particular platform. Reverse engineering is not the way to tackle this problem. – David Heffernan Dec 27 '12 at 20:02
  • @DavidHeffernan Well, you're right about being better to understand every little detail of your application and any of its dependendencies...however, not living in a perfect world can make this difficult sometimes and then those tools do come in handy. – Johannes S. Dec 27 '12 at 21:34
  • I have edited the question to make it clearer, I apologise if the original was a little misleading. I think the edit better represents what I was trying to ask. This answer was very helpful in its own right though, thank you. – Ephemera Dec 28 '12 at 08:53