"C" Example : Hello World Program Package with Dependencies

This example adds dependencies to a package. Dependencies are useful in determining the completeness of installations. Users can be spared obscure errors by doing a dependency check after installing the package[6]. Dependencies can be determined from the source code and the makefile.

Here is the relevent Makefile section


guten-tag-welt: guten-tag-welt.o
        cc -o $@ guten-tag-welt.o -L$(INSTALL_LOCATION)/lib -lhello_world

This shows that the program needs to be linked with the libhello_world.so library from the previous example package. Since this is a shared library, the dependency exists both during package building and runtime. The dependency is expressed as follows


    <Source_Dependencies Type="pgm_link" >
      <Dependency Name="hello_world_c" Package="pgm">
        <Version>
          <Simple_Version Major="0">
          </Simple_Version>
        </Version>
      </Dependency>
    </Source_Dependencies>

The dependency type is 'pgm_link' because we are linking against a program. If we had a guten_tag library that we were linking against, the dependency type would be 'lib_link'. The reason for the type difference is that lib_link dependencies are used by GPT to assemble dependency trees that are then converted into link lines for building programs. pgm_link dependencies should are not used for this. The hello_world_c package which contains the needed library is a 'pgm' package type when built, which indicates the setting for the Package attribute.

The source code reveals two more dependencies. The first is the include statement shown here:

#include "libhello_world.h"

This is a compile dependency to the hello_world_c package. Although this dependency may seem redundant with the linking dependency discussed earlier, it is still a good idea to express it because GPT will check different types of dependencies at different times[7]. The compile dependency is expressed as follows:


    <Source_Dependencies Type="compile" >
      <Dependency Name="hello_world_c" Package="pgm">
       <Version>
        <Simple_Version Major="0">
        </Simple_Version>
       </Version>
      </Dependency>
    </Source_Dependencies>

The last dependency is revealed in the source code with the system command:

    system("$GPT_INSTALL_LOCATION/bin/hello-world.pl");

This shows that the script is executing the hello-world.pl script from the first two example packages. The dependency is a runtime dependency type and is expressed as follows:


    <Source_Dependencies Type="pgm_runtime" >
      <Dependency Name="hello_world" Package="pgm">
       <Version>
        <Simple_Version Major="0">
        </Simple_Version>
       </Version>
      </Dependency>
    </Source_Dependencies>

One thing to note is that because we chose the Simple_Version compatiblity element, the dependency can be fulfilled by either of the first two example packages depending on which one is installed.

The complete set of files for this package can be found here.



[6] More importantly, you can be spared attempting to debug obscure deployment errors in support of end users.

[7] If the package is linking against a library that is always deployed statically then only a compile dependency needs to be expressed. However if the library is deployed as shared or both then both compile and linking dependencies should be expressed to cover both build and runtime deployment.