Changes between Version 1 and Version 2 of VincentTrial2


Ignore:
Timestamp:
May 11, 2005, 3:53:38 PM (19 years ago)
Author:
garonne
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • VincentTrial2

    v1 v2  
     1= A simple example with package dependency =
     2
     3
    14We illustrate here a simple example of package dependency.
    25We show how CMT deals with a package dependency between
    36the package A and B.
     7
     8First we create a directory:
     9{{{
     10> mkdir tmp
     11> cd tmp
     12}}}
    413
    514Let's consider a package A:
     
    4352macro A_linkopts " -L$(AROOT)/$(A_tag) -lA "
    4453}}}
    45 
     54We construct here only the library of the class A.
    4655The macro A_linkopts will be automaticaly inserted for the link operation.
    4756The library location is specified with $(AROOT)/$(A_tag).
    4857
     58Then we create the B package:
     59{{{
     60> cd ../../..
     61> cmt create B v1
     62...
     63}}}
     64
     65With the following content:
     66{{{
     67> cd B/v1/src
     68> more B.h
     69#include <iostream>
     70
     71using namespace std;
     72
     73class B
     74{
     75    public:
     76        B() {}
     77        ~B()  {}
     78        void print ();
     79};
     80> more B.cxx
     81include "B.h"
     82
     83void B::print ()
     84{
     85        cout<<"B"<<endl;
     86}
     87}}}
     88and the main program which needs A and B:
     89{{{
     90> more main.cxx
     91#include "A.h"
     92#include "B.h"
     93int main()
     94{
     95    A a;
     96    B b;
     97   
     98    a.print ();
     99    b.print ();
     100
     101    return 0;
     102}
     103}}}
     104
     105We express this dependency in the requirements file:
     106{{{
     107> cd ../cmt
     108> more requirements
     109package B
     110
     111author Vincent Garonne <garonne@lal.in2p3.fr>
     112
     113use A v1
     114
     115application main main.cxx B.cxx
     116}}}
     117The line "use A v1" says explicitely that package B need pacckage A version 1.
     118The line "application  main main.cxx B.cxx" annouces to CMT that a program must be created and for this creation,
     119we need the file main.cxx and B.cxx.
     120
     121Then to construct the main program with CMT, we first need to give a way to localize the package A.
     122This could be done by the environment variable CMTPATH. This variable contains a list of file paths where CMT
     123package can be found, very similar to the PATH unix environment variable. In our case, we have:
     124{{{
     125> cd ../../../../tmp
     126> setenv CMTPATH  `pwd`
     127> echo $CMTPATH ~garonne/tmp
     128}}}
     129We can see also all the package depencies by the command:
     130{{{
     131> cd B/v1/cmt
     132> cmt show uses
     133# use A v1
     134#
     135# Selection :
     136use CMT v1r18p20050501 (/users/dsksi/garonne)
     137use A v1  (/users/dsksi/garonne/tmp)
     138package A
     139}}}
     140
     141Now we can generate our executable by CMT:
     142{{{
     143> cmt broadcast make
     144...
     145}}}
     146Our executable is now create for you in the Linux-i686 directory:
     147{{{
     148 > ls ../Linux-i686/*.exe
     149../Linux-i686/main.exe
     150}}}
     151To execute we need first to set the LD_LIBRARY_PATH as illustrated:
     152{{{
     153> ../Linux-i686/main.exe
     154../Linux-i686/main.exe: error while loading shared libraries: libA.so: cannot open shared object file: No such file or directory
     155> setenv LD_LIBRARY_PATH ../../../A/v1/Linux-i686/
     156> ../Linux-i686/main.exe
     157A
     158B
     159}}}
     160
     161If we want to compile in a static way, we should add to the B requirements the macro "B_linkopts" :
     162{{{
     163> more ../cmt/requirements
     164package B
     165
     166author Vincent Garonne <garonne@lal.in2p3.fr>
     167
     168use A v1
     169
     170application main main.cxx B.cxx
     171
     172macro B_linkopts " -static "
     173> unsetenv LD_LIBRARY_PATH
     174> ../Linux-i686/main.exe
     175A
     176B
     177}}}
     178
     179By this way, the LD_LIBRARY is not mandatory anymore.
     180
     181Another solution could be also to use only libraries for compiling, by example:
     182{{{
     183> more ../cmt/requirements
     184package B
     185
     186author Vincent Garonne <garonne@lal.in2p3.fr>
     187
     188use A v1
     189
     190application main main.cxx
     191
     192library  B B.cxx
     193
     194macro B_linkopts " -L$(BROOT)/$(B_tag) -lB "
     195}}}
     196The B library should be also create.
     197
     198
     199
     200
     201}}}
     202
     203