[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with static linking
From: |
Kip Warner |
Subject: |
Re: Help with static linking |
Date: |
Mon, 03 Jun 2013 22:30:33 -0700 |
On Mon, 2013-06-03 at 17:06 -0400, Paul Smith wrote:
> I can't think of any reason why adding those flags would cause this to
> happen. Indeed, I can't think of any reason why ld-linux.so would NOT
> be linked with your application before these flags were added. I would
> have thought that any executable that had any dynamic libraries linked
> at all would need this (it's the runtime linker).
Who knows. I can't seem to explain it either. =P
> Are you sure that library didn't used to exist in the ldd output? If
> so, were you linking your executable statically (no shared libs) before?
This is what I see when I run ./configure --enable-dbus-interface &&
make && objdump -p ./viking-extractor
...
Dynamic Section:
NEEDED libgio-2.0.so.0
NEEDED libgobject-2.0.so.0
NEEDED libglib-2.0.so.0
NEEDED libpng12.so.0
NEEDED libzzip-0.so.13
NEEDED libstdc++.so.6
NEEDED libm.so.6
NEEDED libgcc_s.so.1
NEEDED libpthread.so.0
NEEDED libc.so.6
...
And with --enable-static appended to ./configure...
...
Dynamic Section:
NEEDED libgio-2.0.so.0
NEEDED libgobject-2.0.so.0
NEEDED libglib-2.0.so.0
NEEDED libm.so.6
NEEDED libpthread.so.0
NEEDED libc.so.6
NEEDED ld-linux-x86-64.so.2
...
I should add that I defined some logic for --enable-static in
configure.ac as such...
# D-Bus interface...
AC_ARG_ENABLE([static],
[AS_HELP_STRING([--enable-static],
[enable static compilation @<:@default: no@:>@])],
[static=${enableval}],
[static=no])
...
# zziplib...
# Check for C header and library...
if test "$static" = yes; then
PKG_CHECK_MODULES_STATIC([libzzip], [zziplib], [have_zzip=yes],
[have_zzip=no])
else
PKG_CHECK_MODULES([libzzip], [zziplib], [have_zzip=yes], [have_zzip=no])
fi
if test "x${have_zzip}" = xno; then
AC_MSG_ERROR([zziplib runtime library is required, but was not
detected...])
fi
# Store the needed compiler flags for automake since this doesn't happen
# automatically like with AC_CHECK_LIB. We will take care of linker
# flags later...
CXXFLAGS="$CXXFLAGS $libzzip_CFLAGS"
# Portable network graphics...
# Check for C++ interface header...
AC_CHECK_HEADERS([png++/png.hpp], [have_png_cxx=yes], [have_png_cxx=no])
if test "x${have_png_cxx}" = xno; then
AC_MSG_ERROR([libpng++ headers are required, but were not detected...])
fi
# Check for C header and static library...
if test "$static" = yes; then
PKG_CHECK_MODULES_STATIC([libpng], [libpng], [have_png=yes],
[have_png=no])
else
PKG_CHECK_MODULES([libpng], [libpng], [have_png=yes], [have_png=no])
fi
if test "x${have_png}" = xno; then
AC_MSG_ERROR([libpng runtime library is required, but was not
detected...])
fi
# Store the needed compiler flags for automake since this doesn't happen
# automatically like with AC_CHECK_LIB. We will take care of linker
# flags later...
CXXFLAGS="$CXXFLAGS $libpng_CFLAGS"
...
# Set additional linker flags...
# If static compilation is enabled, update linker...
if test "$static" = yes; then
# libpng and libzzip statically link against...
LIBS="$LIBS -Wl,-Bstatic $libpng_LIBS $libzzip_LIBS -Wl,-Bdynamic"
# Static linking against GCC's runtimes and the standard C++ library...
LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
# Otherwise insert vanilla linker flags...
else
LIBS="$LIBS $libpng_LIBS $libzzip_LIBS"
fi
...
# If static compilation is enabled, update linker...
if test "$static" = yes; then
# libpng and libzzip statically link against...
LIBS="$LIBS -Wl,-Bstatic $libpng_LIBS $libzzip_LIBS -Wl,-Bdynamic"
# Static linking against GCC's runtimes and the standard C++ library...
LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
# Otherwise insert vanilla linker flags...
else
LIBS="$LIBS $libpng_LIBS $libzzip_LIBS"
fi
So that's the solution I've come up with so far and it seems to work,
but I'm open to better solutions.
> Anyway, seeing that library doesn't bother me.
>
> > I wonder if I could do this for a GNU/Linux i386 binary and amd64, and a
> > w32 binary via mingw sysroot, if such a thing is possible.
>
> It is certainly possible to create a cross-compilation environment to
> build Windows/mingw output on a Linux system; indeed it's becoming a
> very popular way of handling Windows targets. Some google searching
> will lead you to many examples and write-ups; I don't have anything
> handy that I've tried and can attest to unfortunately.
>
> However, it WON'T be as simple as you describe above. Just having a
> different sysroot won't be enough: you'll have to actually create a
> separate cross-compiler toolchain as well. That's because all the
> Linux-based distributions use the same basic executable layout, calling
> structure, etc. (ELF). So, the only real difference from a compiler
> standpoint between Red Hat, Debian, etc. are the versions of the various
> shared libraries that are installed.
Alright. Noted.
> Windows, on the other hand uses an entirely different layout for its
> executables and libraries. It's far more than just some library version
> differences: you need a whole different compiler.
Thankfully it looks as though there are precompiled MinGW debs available
for my distribution (Ubuntu Raring / amd64) and hopefully I'll be able
to get them up and running.
--
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
signature.asc
Description: This is a digitally signed message part