Ligcc

What is ligcc?

Ligcc is a wrapper around gcc. It allows you to create more portable executables by doing three things:

  • Forces the linker to link against older glibc symbols. Users who are using an older version of glibc will no longer get “undefined symbol GLIBC_2.4 in /lib/libc.so”-style error messages.
  • Allows you to easily statically link to any other library.
  • Automatically removes bogus dependencies. For example, your program uses libfoo. libfoo uses libpng internally, but your app does not. Yet the pkg-config file for libfoo specifies ”-lfoo -lpng” is linker parameters. And tadaa - you now have a bogus dependency on libpng! Ligcc automatically removes the -lpng for you if your app doesn't use libpng directly.
    It is recommended that you use binutils 2.15.94 or later to compile programs, recent versions of ld support the –as-needed argument, which does a much better job than our own dependency stripper, and is faster too.
  • Add $ORIGIN/../lib to the binary's library search path. $ORIGIN is the directory in which the binary exists. This ensures that your binary can find its library dependencies if they are placed in the 'lib' folder under the same prefix. You can drop any dependency library you want in $PREFIX/lib/. Your binary can find those libraries without messing with $LD_LIBRARY_PATH.
  • If you set $LIBUILD_PROJECTNAME, ligcc will also add $ORIGIN/../lib/$LIBUILD_PROJECTNAME to the library search path.

How to use ligcc?

Use ligcc just like how you use gcc. Examples:

ligcc foo.c -o foo
lig++ bar.cpp -o bar

Recommended way:

export CC=ligcc
export CXX=lig++
./configure
make
make CC=ligcc CXX=lig++

There are several environment variables that change ligcc's behavior:

LIBUILD_PATH

Use this as the include dir for the ligcc headers. Default value: $PREFIX/include/libuild (where $PREFIX is the prefix in which libuild is installed)

LIBUILD_CC

Use the specified C compiler. Default value: gcc

LIBUILD_CXX1

Use the specified C++ compiler. Default value: g++

LIBUILD_STATIC_X

If set to 1, then libuild will statically link some X extension libraries.

LIBUILD_BOGUS_DEPS

Specify a list of whitespace-seperated bogus library dependencies (like: X11 ICE png). These libraries will not be linked against. This option is useful if you want to specify bogus dependencies manually because the automatic bogus dependency stripper doesn't work correctly for your project (see below).

LIBUILD_DISABLE_BOGUS_DETECTOR

If set to 1, disables the automatic bogus dependency stripper. This is useful when linking to libraries don't have correct DT_NEEDED entries, like GTK 1.2. GTK 1.2 uses libX11.so internally, but it's not linked with -lX11. Instead, gtk-config –libs returns -lgtk -lX11 or something. If your app doesn't use xlib internally, then our bogus dependency stripper will strip the -lX11 argument. Linking will then fail.

The built-in bogus dependency stripper is not used if you have a recent version of binutils, which supports ld –as-needed (it'll use binutil's native support for bogus dependency stripping instead). So you should get use a recent version of binutils if your ld doesn't already support that argument.

LIBUILD_NOT_BOGUS

If you want to use the automatic bogus dependency dectector anyway (using ld –asneeded), then you can specify a list of dependencies here that are not bogus with this environment variable. Example:

export LIBUILD_NOT_BOGUS="X11 ICE png"
LIBUILD_STATIC

Specify a list of whitespace-seperated libraries to statically link to (like: popt z). You can also explicitly specify a filename to the static library. Examples:

export LIBUILD_STATIC="popt z"
export LIBUILD_STATIC="popt=/usr/lib/libpopt.a"
LIBUILD_STATIC_LIBGCC

If set to 1, link all binaries with -static-libgcc. See the gcc info page for more info about this option.

LIBUILD_PROJECTNAME

If non-empty, ligcc will add $ORIGIN/../lib/$LIBUILD_PROJECTNAME to the library search path.

LIBUILD_INCLUDE

Prepend the specified directory to the compiler's header search path. The compiler will search this directory first, before searching any other directory. This is useful in combination with the older GTK headers package. You can specify multiple directories, seperated by a ':', just like the $PATH environment variable. If the order of the -I flags is important for your application, you can replace paths by using /old/path=/new/path.

LIBUILD_RESOLVE_LIBPATH

A space-seperated list of (Perl) regular expressions which specify the libraries whose path must be resolved into absolute paths.

Internally, ligcc reorders the linking arguments that are to be passed to gcc (for various reasons). This can cause problems when linking certain static libraries (for example, static WxWidgets libraries). But that can be worked around by using full path names for static libraries (e.g. turning '-lfoo' parameters into /usr/lib/full-path-to/foo.a).

ligcc.txt · Last modified: 2012/04/23 20:57 by Matthias Klumpp
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0