Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requirements for shipping runtime libraries/DLLs

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.

like image 810
Ephemera Avatar asked Dec 24 '12 02:12

Ephemera


People also ask

Is DllMain required?

The DllMain function is an optional method of entry into a dynamic-link library (DLL). If the function is used, it is called by the system when processes and threads are initialized and terminated, or upon calls to LoadLibrary and FreeLibrary.

Which library helps us to provide runtime details of our application?

Open Source, Embedded Linux, and Android The compiler support library is called libgcc and is provided by the compiler itself to supply low-level compiler support routines such as software floating-point emulation and support for exception-handling. This library is used by virtually all programs compiled with GCC.

What is DLL import library?

An import library (. lib) file contains information the linker needs to resolve external references to exported DLL functions, so the system can locate the specified DLL and exported DLL functions at run time. You can create an import library for your DLL when you build your DLL.

What are runtime library files?

A runtime library is a collection of software programs used at program run time to provide one or more native program functions or services.


2 Answers

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.

like image 192
David Grayson Avatar answered Sep 27 '22 22:09

David Grayson


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.

like image 33
edifice Avatar answered Sep 28 '22 00:09

edifice