CMake Questions

Thiago Macieira thiago at kde.org
Mon Mar 20 17:17:50 GMT 2006


Alexander Neundorf wrote:
>On Sunday 19 March 2006 20:54, Szombathelyi György wrote:
>> What I still found missing from cmake, is the support for the
>> --as-needed and --enable-new-dtags linker flag. (--enable-new-ldflags
>> with autoconf/automake).
>
>Ok, if we need these flags we can add them. What do these flags do ?

--as-needed:
  Instructs the linker to check which libraries symbols it imports are 
from. This means that if I link my program:

#include <QtCore/QCoreApplication>
int main(int argc, char **argv)
{
  QCoreApplication app(argc,argv);
  return 0;
}

with the libraries: -lQtCore -lQtGui -lkdecore -lkdeui -lkio

the linker will realise that my program only imports symbols 
from "libQtCore.so.4", so it'll add the DT_NEEDED entry for 
libQtCore.so.4 only.

With --no-as-needed (the default), the compiler would produce:
  NEEDED libQtCore.so.4
  NEEDED libQtGui.so.4
  NEEDED libkdecore.so.5
  NEEDED libkdeui.so.5
  NEEDED libkio.so.5

And those libraries would be loaded at run-time, with their initialisation 
routines performed (think static variables constructed with function 
calls or static objects).

Needless to say it's expensive and unnecessary. However, it doesn't come 
without its own share of side-effects. When we tried to make it the 
default in KDE, we ended up with problems when trying to run uninstalled 
binaries. The reason for that is that the library search path for 
indirect libraries (libraries-required-by-libraries but not your program) 
would be different and you'd end up loading the wrong ones.

This should be solvable with LD_LIBRARY_PATH, which in turn brings us to:

--enable-new-dtags:
  Instructs the linker to use the new dtags (DT_* entries) in the ELF 
header, including DT_RUNPATH. I've explained over and over again the 
difference between DT_RPATH and DT_RUNPATH. I expect you to 
have --enable-new-dtags enabled by default in cmake, since the "install" 
rpath mode sets LD_LIBRARY_PATH instead of relinking.

Setting LD_LIBRARY_PATH has NO EFFECT if you didn't use --enable-new-dtags 
and used --rpath.

-- 
Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
  thiago.macieira (AT) trolltech.com     Trolltech AS
    GPG: 0x6EF45358                   |  Sandakerveien 116,
    E067 918B B660 DBD1 105C          |  NO-0402
    966C 33F5 F005 6EF4 5358          |  Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060320/c9cb23ff/attachment.sig>


More information about the kde-core-devel mailing list