[Gllug] library includes and compiling

Nix nix at esperi.demon.co.uk
Thu Jan 10 00:22:49 UTC 2002


On Tue, 08 Jan 2002, Jonathan Dye spake:
> I'm trying to compile against the OpenGL libraries in /usr/X11R6/lib by doing
> 
> gcc source.c -lGL

yuck. ITYM

gcc -O2 -Wall -ansi -pedantic -o source source.c -L/usr/X11R6/lib -lGL

if, that is, you want good warnings and so forth... GCC generates truly
*appalling* code at -O0, and in GCC<=2.9x, some warnings are only
emitted at -O1 and above (because flow analysis isn't done at -O0).

> but it doesn't find them.  I have /usr/X11R6/lib in /etc/ld.so.conf and
> I've run ldconfig. I guess that this is related to run-time linking though
> rather than compile-time linker search directories because it doesn't help.

Quite so, ldconfig converts /etc/ld.so.conf into /etc/ld.so.cache,
wwhich is read by ld-linux.so.2 at runtime.

> I can compile using
> 
> gcc source.c -L/usr/X11R6/lib -lGL
> 
> but I was hoping to aviod this if possible.

You cannot --- at least, not portably. use -L/usr/X11R6/lib, and your
program will build anywhere with X11R6.

(except that you'll almost certainly need at least -lGL -lX11, and you
may well need -lICE and -lXext as well. Oh, and don't forget to consider
MesaGL <=3.2 as well, which called the library -lMesaGL instead... the
death of portability by a thousand cuts...)

--- but there *are* a few horrendously ugly kludges you could use. Don't
use them, but here they are anyway ('cos I'm bored):

- You could make symlinks in /usr/lib pointing to /usr/X11R6/lib/*.so;
  this is the only file that the linker searches for. Disadvantages: only
  root can do this so you can't compile your program on sites that
  haven't done this.

- You could modify the GCC specs file (see `gcc -print-file-name=specs')
  to always include -L/usr/X11R6/lib in the path passed to the linker;
  the line to look for in there is the *link: line. Disadvantages: specs
  files are highly GCC version, host, and target-specific, so you'd need
  to drag a bunch of customized specs files around with you
  everywhere. They'll probably also be disappearing completely soon
  (their impact on the performance of the GCC driver is *horrible*,
  scaling O(n^2) as the number of switches rises). Specs files don't
  exist for non-GCC compilers at all, either, so you'd be locking
  yourself to GCC. (Not exactly a terrible thing, I think, but you may
  disagree.)

- You could modify the GNU ld script file to search a larger set of
  directories (the option name is SEARCH_DIR). Checking this can be
  useful anyway to work out where the damn thing is *looking* for .so
  and .a files; normally it searches /lib, /usr/lib, /usr/local/lib, and
  {$prefix}/${arch-triplet}/lib, in that order. Disadvantages: Relies
  upon the C compiler using GNU ld, requires you to find the damn script
  files (normally in ${prefix}/{arch-triplet}/lib/ldscripts/, but can be
  anywhere depending upon how ld was built), and requires you to know
  which script ld is using, which varies from tricky to very hard,
  because it might also be using an internal one compiled into ld.

But this is all academic, because you'd never want to do any of these
things because of all their disadvantages. But still, if you really
needed to, you *could*. ;}

I *like* Unix. This flexibility... (although it would be nice if some of
the flexibility was a little less arcane and hard to find. Having the
source is *so* *damn* *useful*... OK, maybe `I like free Unix' is more
accurate. :) )

-- 
`Perhaps you should have asked Santa for your program as a Christmas
present.' --- Terran Melconian

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list