wiki:VincentTrial2

A simple example with package dependency

We illustrate here a simple example of package dependency. We show how CMT deals with a package dependency between package A and B.

First we create a directory:

> mkdir tmp
> cd tmp

Let's consider a package A:

> cmt create A V1
...
> cd A/v1/src
...
> more A.h
#include <iostream>

using namespace std;

class A
{
    public:
	A() {}
	~A()  {}
	void print ();
};
> more A.cxx
#include "A.h"

void A::print ()
{
	cout<<"A"<<endl;
}

We have the following requirement file:

> cd cmt
> more requirements
package A

author Vincent Garonne <garonne@lal.in2p3.fr>

library A A.cxx

macro A_linkopts " -L$(AROOT)/$(A_tag) -lA "

We construct here only the library of the class A. The macro A_linkopts will be automaticaly inserted for the link operation. The library location is specified with $(AROOT)/$(A_tag).

Then we create the B package:

> cd ../../..
> cmt create B v1
...

With the following content:

> cd B/v1/src
> more B.h
#include <iostream>

using namespace std;

class B
{
    public:
	B() {}
	~B()  {}
	void print ();
};
> more B.cxx
include "B.h"

void B::print ()
{
	cout<<"B"<<endl;
}

and the main program which needs A and B:

> more main.cxx
#include "A.h"
#include "B.h"
int main()
{
    A a;
    B b;
    
    a.print ();
    b.print ();

    return 0;
}

We express this dependency in the requirements file:

> cd ../cmt
> more requirements
package B

author Vincent Garonne <garonne@lal.in2p3.fr>

use A v1

application main main.cxx B.cxx

The line "use A v1" says explicitely that package B needs package A version 1. The line "application main main.cxx B.cxx" annouces to CMT that a program must be created and for this creation, we need the files main.cxx and B.cxx.

Then to construct the main program with CMT, we first need to give a way to localize the package A. This could be done by the environment variable CMTPATH. This variable contains a list of file paths where CMT package can be found, very similar to the PATH unix environment variable. In our case, we have:

> cd ../../../../tmp
> setenv CMTPATH  `pwd`
> echo $CMTPATH ~garonne/tmp

We can see also all the package dependencies by the command:

> cd B/v1/cmt
> cmt show uses
# use A v1 
#
# Selection :
use CMT v1r18p20050501 (/users/dsksi/garonne)
use A v1  (/users/dsksi/garonne/tmp)
package A

Now we can generate our executable by CMT:

> cmt broadcast make
...

Our executable is now create for you in the Linux-i686 directory:

 > ls ../Linux-i686/*.exe
../Linux-i686/main.exe

To execute we need first to set the LD_LIBRARY_PATH as illustrated:

> ../Linux-i686/main.exe
../Linux-i686/main.exe: error while loading shared libraries: libA.so: cannot open shared object file: No such file or directory
> setenv LD_LIBRARY_PATH ../../../A/v1/Linux-i686/
> ../Linux-i686/main.exe
A
B

If we want to compile in a static way, we should add to the B requirements the macro "B_linkopts" :

> more ../cmt/requirements
package B

author Vincent Garonne <garonne@lal.in2p3.fr>

use A v1

application main main.cxx B.cxx

macro B_linkopts " -static "
> unsetenv LD_LIBRARY_PATH
> ../Linux-i686/main.exe
A
B 

By this way, the LD_LIBRARY is not mandatory anymore.

Another solution could be also to use only libraries for compiling, by example:

> more ../cmt/requirements
package B

author Vincent Garonne <garonne@lal.in2p3.fr>

use A v1

application main main.cxx 

library  B B.cxx

macro B_linkopts " -L$(BROOT)/$(B_tag) -lB "

The B library should be also create.

We want now to do the same but inside a CMT project area A example of project creation.

Last modified 19 years ago Last modified on May 11, 2005, 4:06:30 PM