| | 58 | Then we create the B package: |
| | 59 | {{{ |
| | 60 | > cd ../../.. |
| | 61 | > cmt create B v1 |
| | 62 | ... |
| | 63 | }}} |
| | 64 | |
| | 65 | With the following content: |
| | 66 | {{{ |
| | 67 | > cd B/v1/src |
| | 68 | > more B.h |
| | 69 | #include <iostream> |
| | 70 | |
| | 71 | using namespace std; |
| | 72 | |
| | 73 | class B |
| | 74 | { |
| | 75 | public: |
| | 76 | B() {} |
| | 77 | ~B() {} |
| | 78 | void print (); |
| | 79 | }; |
| | 80 | > more B.cxx |
| | 81 | include "B.h" |
| | 82 | |
| | 83 | void B::print () |
| | 84 | { |
| | 85 | cout<<"B"<<endl; |
| | 86 | } |
| | 87 | }}} |
| | 88 | and the main program which needs A and B: |
| | 89 | {{{ |
| | 90 | > more main.cxx |
| | 91 | #include "A.h" |
| | 92 | #include "B.h" |
| | 93 | int main() |
| | 94 | { |
| | 95 | A a; |
| | 96 | B b; |
| | 97 | |
| | 98 | a.print (); |
| | 99 | b.print (); |
| | 100 | |
| | 101 | return 0; |
| | 102 | } |
| | 103 | }}} |
| | 104 | |
| | 105 | We express this dependency in the requirements file: |
| | 106 | {{{ |
| | 107 | > cd ../cmt |
| | 108 | > more requirements |
| | 109 | package B |
| | 110 | |
| | 111 | author Vincent Garonne <garonne@lal.in2p3.fr> |
| | 112 | |
| | 113 | use A v1 |
| | 114 | |
| | 115 | application main main.cxx B.cxx |
| | 116 | }}} |
| | 117 | The line "use A v1" says explicitely that package B need pacckage A version 1. |
| | 118 | The line "application main main.cxx B.cxx" annouces to CMT that a program must be created and for this creation, |
| | 119 | we need the file main.cxx and B.cxx. |
| | 120 | |
| | 121 | Then to construct the main program with CMT, we first need to give a way to localize the package A. |
| | 122 | This could be done by the environment variable CMTPATH. This variable contains a list of file paths where CMT |
| | 123 | package 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 | }}} |
| | 129 | We 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 : |
| | 136 | use CMT v1r18p20050501 (/users/dsksi/garonne) |
| | 137 | use A v1 (/users/dsksi/garonne/tmp) |
| | 138 | package A |
| | 139 | }}} |
| | 140 | |
| | 141 | Now we can generate our executable by CMT: |
| | 142 | {{{ |
| | 143 | > cmt broadcast make |
| | 144 | ... |
| | 145 | }}} |
| | 146 | Our executable is now create for you in the Linux-i686 directory: |
| | 147 | {{{ |
| | 148 | > ls ../Linux-i686/*.exe |
| | 149 | ../Linux-i686/main.exe |
| | 150 | }}} |
| | 151 | To 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 |
| | 157 | A |
| | 158 | B |
| | 159 | }}} |
| | 160 | |
| | 161 | If we want to compile in a static way, we should add to the B requirements the macro "B_linkopts" : |
| | 162 | {{{ |
| | 163 | > more ../cmt/requirements |
| | 164 | package B |
| | 165 | |
| | 166 | author Vincent Garonne <garonne@lal.in2p3.fr> |
| | 167 | |
| | 168 | use A v1 |
| | 169 | |
| | 170 | application main main.cxx B.cxx |
| | 171 | |
| | 172 | macro B_linkopts " -static " |
| | 173 | > unsetenv LD_LIBRARY_PATH |
| | 174 | > ../Linux-i686/main.exe |
| | 175 | A |
| | 176 | B |
| | 177 | }}} |
| | 178 | |
| | 179 | By this way, the LD_LIBRARY is not mandatory anymore. |
| | 180 | |
| | 181 | Another solution could be also to use only libraries for compiling, by example: |
| | 182 | {{{ |
| | 183 | > more ../cmt/requirements |
| | 184 | package B |
| | 185 | |
| | 186 | author Vincent Garonne <garonne@lal.in2p3.fr> |
| | 187 | |
| | 188 | use A v1 |
| | 189 | |
| | 190 | application main main.cxx |
| | 191 | |
| | 192 | library B B.cxx |
| | 193 | |
| | 194 | macro B_linkopts " -L$(BROOT)/$(B_tag) -lB " |
| | 195 | }}} |
| | 196 | The B library should be also create. |
| | 197 | |
| | 198 | |
| | 199 | |
| | 200 | |
| | 201 | }}} |
| | 202 | |
| | 203 | |