[CMake] Changing installation prefix triggers re-linking of all libraries

Alexander Neundorf a.neundorf-work at gmx.net
Fri Apr 29 14:25:48 EDT 2011


On Friday 29 April 2011, Pere Mato Vila wrote:
> Perhaps somebody can give me some hints on this problem I have. I build a
> project and install it in <path>/install with "make install".  Then I do
> change the installation prefix with cmake
> -DCMAKE_INSTALL_PREFIX=<path>/install2 ../root_cmake/
> and if I execute again "make install" it rebuilds basically every library
> of the project.  I have traced the dependency to the generated link.txt
> file, which contains the link command. In one case the contents of the file
> is:
>
> /usr/bin/c++  -fPIC  -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -O2 -g 
> -shared -Wl,-soname,libCint.so -o ../../lib/libCint.so
> CMakeFiles/Cint.dir/src/loadfile.o ../../lib/libCint_static.a -lpthread
> -Wl,-rpath,::::::::::::::::::::::::::::
>
> and in the other is:
>
> /usr/bin/c++  -fPIC  -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -O2 -g 
> -shared -Wl,-soname,libCint.so -o ../../lib/libCint.so
> CMakeFiles/Cint.dir/src/loadfile.o ../../lib/libCint_static.a -lpthread
> -Wl,-rpath,:::::::::::::::::::::::::::::
>
> Notice the different number of colons in the -rpath settings. The first
> question I have is what is the origin of these many colons in the rpath
> settings? 

When cmake builds a binary, it builds it by default with the build RPATH. This 
means in the ELF header the entry for the RPATH is created as long as 
necessary.
When installing, cmake then patches the build RPATH out of the binaries and 
replaces it with the install RPATH.

Now if the install RPATH is longer than the build RPATH, the build RPATH is 
filled up with colons until it is long enough so that at make install cmake 
can successfully write the install RPATH in this location.

In your case, the build RPATH is empty. This seems to be the case because your 
libCint.so doesn't link against any other shared libraries.
Then you set the install RPATH once to "/build/mato/ROOT/install/lib" and then 
to "/build/mato/ROOT/install2/lib", which is one byte longer. So the binary 
has to be created again with one byte more room for the install RPATH.

Are you sure you actually need this RPATH in this library ? In the link 
command you posted there are no libraries linked...

Alex


More information about the CMake mailing list