Subject: libtool is picking the wrong path for dependent libraries

From: Roger Nichols <[email-masked]>
Date: Fri, 15 Jul 2011 22:58:26 -0400

hi,

i dont know if i have a bug, or user error.  i am cross compiling
openhpi (and openipmi) into a root file system.  the libtool command
does not have the build host system's libraries in the -L arguments,
yet the libraries are explicitly pathed to the build host's versions.
even if i use --with-openipmi=/path/to/openipmi, since the libs are
added to the link line with -L -l -l, libtool seems to search for the
libs and explicitly path them.  is this a bug?  or how do i get libtool
to use the cross compiled libraries?

here is the libtool command, and the resultant link line.  (the spacing
is mine so i could see what was happening.  the output's order _is_
preserved.)

thanks for your help
--roger

/bin/sh ../../libtool --tag=CC   --mode=link 
    /opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-gcc
    -m32 -mhard-float -mmultiple -mno-string -mcpu=7450 -O0 -D_REENTRANT
    -I/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/include/glib-2.0
    -I/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib/glib-2.0/include
    -Wall -Wmissing-prototypes -Wmissing-declarations
    -Wstrict-prototypes -Wpointer-arith -Wformat=2 -Wformat-security
    -Wformat-nonliteral -Wno-format-y2k -Wcast-qual -Wcast-align
    -Wno-strict-aliasing -Wno-unused-value -Werror
    -D_GNU_SOURCE -D_REENTRANT -fexceptions
    -I/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/include
    -m32 -mhard-float -mmultiple -mno-string -mcpu=7450 -O0 -D_REENTRANT
    -I/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/include/glib-2.0
    -I/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib/glib-2.0/include
    -Wall -Wmissing-prototypes -Wmissing-declarations
-Wstrict-prototypes -Wpointer-arith -Wformat=2 -Wformat-security
-Wformat-nonliteral -Wno-format-y2k -Wcast-qual -Wcast-align
-Wno-strict-aliasing -Wno-unused-value -Werror
    -D_GNU_SOURCE -D_REENTRANT -fexceptions -module 
    -version-info 12:2:10
    -export-dymanic ./ipmi.sym
    -L/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib
    -L/home/rnichols/rnichols_gen3p/build_output/PS7100_TOS/openhpi/linux-MPC8641D/install/usr/lib
    -o libipmi.la
    -rpath /usr/lib/openhpi 
    ipmi.lo ipmi_close.lo ipmi_connection.lo ipmi_event.lo
    ipmi_entity_event.lo ipmi_mc_event.lo ipmi_inventory_event.lo
    ipmi_sensor_event.lo ipmi_control_event.lo ipmi_entity.lo 
    ipmi_sensor.lo ipmi_sel.lo ipmi_inventory.lo ipmi_controls.lo
    ipmi_util.lo ipmi_drv.lo hotswap.lo sync.lo posix_vlog.lo
    atca_shelf_rdrs.lo atca_slot_rdrs.lo atca_vshm_rdrs.lo
    atca_fru_rdrs.lo atca_shelf_fru.lo ../../utils/libopenhpiutils.la
    -luuid -lncurses -lOpenIPMI -lOpenIPMIposix 
    -L/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib
    -lOpenIPMIutils -lOpenIPMI -lltdl
    -L/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib
    -lgthread-2.0 -lpthread -lrt -lglib-2.0   -lm -lpthread

libtool: link: warning:
`/home/rnichols/rnichols_gen3p/build_output/PS7100_TOS/openhpi/linux-MPC8641D/install/usr/lib/libOpenIPMIutils.la'
seems to be moved libtool: link: warning:
`/home/rnichols/rnichols_gen3p/build_output/PS7100_TOS/openhpi/linux-MPC8641D/install/usr/lib/libOpenIPMIutils.la'
seems to be moved

/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-gcc -shared
          .libs/ipmi.o .libs/ipmi_close.o .libs/ipmi_connection.o
          .libs/ipmi_event.o .libs/ipmi_entity_event.o 
          .libs/ipmi_mc_event.o .libs/ipmi_inventory_event.o 
          .libs/ipmi_sensor_event.o .libs/ipmi_control_event.o
          .libs/ipmi_entity.o .libs/ipmi_sensor.o .libs/ipmi_sel.o
          .libs/ipmi_inventory.o .libs/ipmi_controls.o .libs/ipmi_util.o
          .libs/ipmi_drv.o .libs/hotswap.o .libs/sync.o .libs/posix_vlog.o 
          .libs/atca_shelf_rdrs.o .libs/atca_slot_rdrs.o 
          .libs/atca_vshm_rdrs.o .libs/atca_fru_rdrs.o 
          .libs/atca_shelf_fru.o

          -Wl,--rpath
          -Wl,/home/rnichols/rnichols_gen3p/build_output/PS7100_TOS/openhpi/linux-MPC8641D/openhpi-2.10.2/utils/.libs
          -Wl,--rpath -Wl,/usr/lib

          -L/opt/timesys/toolchains/ppc86xx-linux/powerpc-timesys-linux-gnu/lib
          -L/home/rnichols/rnichols_gen3p/build_output/PS7100_TOS/openhpi/linux-MPC8641D/install/usr/lib

          ../../utils/.libs/libopenhpiutils.so -luuid -lncurses
          /usr/lib/libOpenIPMIposix.so
          /usr/lib/libOpenIPMIutils.so
          /usr/lib/libOpenIPMI.so
          -lltdl -lgthread-2.0 -lrt -lglib-2.0 -lm -lpthread

          -m32 -mhard-float -mmultiple -mno-string -mcpu=7450
          -m32 -mhard-float -mmultiple -mno-string -mcpu=7450

          -Wl,-soname -Wl,libipmi.so.2 -o .libs/libipmi.so.2.10.2

/usr/lib/libOpenIPMIposix.so: could not read symbols: File in wrong
format

$ ./libtool --version
ltmain.sh (GNU libtool) 1.5.24 (1.1220.2.456 2007/06/24 02:25:32)

Copyright (C) 2007  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
$ ./libtool --config link

# Libtool was configured on host williams:

# Shell to use when invoking shell scripts.
SHELL="/bin/sh"

# Whether or not to build shared libraries.
build_libtool_libs=yes

# Whether or not to build static libraries.
build_old_libs=yes

# Whether or not to add -lc for building shared libraries.
build_libtool_need_lc=no

# Whether or not to disallow shared libs when runtime libs are static
allow_libtool_libs_with_static_runtimes=no

# Whether or not to optimize for fast installation.
fast_install=yes

# The host system.
host_alias=powerpc-linux
host=powerpc-unknown-linux-gnu
host_os=linux-gnu

# The build system.
build_alias=
build=x86_64-unknown-linux-gnu
build_os=linux-gnu

# An echo program that does not interpret backslashes.
echo="echo"

# The archiver.
AR="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-ar"
AR_FLAGS="cru"

# A C compiler.
LTCC="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-gcc"

# LTCC compiler flags.
LTCFLAGS="-m32 -mhard-float -mmultiple -mno-string -mcpu=7450 -O0"

# A language-specific compiler.
CC="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-gcc"

# Is the compiler the GNU C compiler?
with_gcc=yes

# An ERE matcher.
EGREP="/bin/grep -E"

# The linker used to build libraries.
LD="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-ld"

# Whether we need hard or soft links.
LN_S="ln -s"

# A BSD-compatible nm program.
NM="nm"

# A symbol stripping program
STRIP="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-strip"

# Used to examine libraries when file_magic_cmd begins "file"
MAGIC_CMD=file

# Used on cygwin: DLL creation program.
DLLTOOL="dlltool"

# Used on cygwin: object dumper.
OBJDUMP="objdump"

# Used on cygwin: assembler.
AS="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-as"

# The name of the directory that contains temporary libtool files.
objdir=.libs

# How to create reloadable object files.
reload_flag=" -r"
reload_cmds="\$LD\$reload_flag -o \$output\$reload_objs"

# How to pass a linker flag through the compiler.
wl="-Wl,"

# Object file suffix (normally "o").
objext="o"

# Old archive suffix (normally "a").
libext="a"

# Shared library suffix (normally ".so").
shrext_cmds='.so'

# Executable file suffix (normally "").
exeext=""

# Additional compiler flags for building library objects.
pic_flag=" -fPIC -DPIC"
pic_mode=default

# What is the maximum length of a command?
max_cmd_len=98304

# Does compiler simultaneously support -c and -o options?
compiler_c_o="yes"

# Must we lock files when doing compilation?
need_locks="no"

# Do we need the lib prefix for modules?
need_lib_prefix=no

# Do we need a version for libraries?
need_version=no

# Whether dlopen is supported.
dlopen_support=yes

# Whether dlopen of programs is supported.
dlopen_self=unknown

# Whether dlopen of statically linked programs is supported.
dlopen_self_static=unknown

# Compiler flag to prevent dynamic linking.
link_static_flag="-static"

# Compiler flag to turn off builtin functions.
no_builtin_flag=" -fno-builtin"

# Compiler flag to allow reflexive dlopens.
export_dynamic_flag_spec="\${wl}--export-dynamic"

# Compiler flag to generate shared objects directly from archives.
whole_archive_flag_spec="\${wl}--whole-archive\$convenience
\${wl}--no-whole-archive"

# Compiler flag to generate thread-safe objects.
thread_safe_flag_spec=""

# Library versioning type.
version_type=linux

# Format of library name prefix.
libname_spec="lib\$name"

# List of archive names.  First name is the real one, the rest are
links. # The last name is the one that the linker finds with -lNAME.
library_names_spec="\${libname}\${release}\${shared_ext}\$versuffix
\${libname}\${release}\${shared_ext}\$major \$libname\${shared_ext}"

# The coded name of the library, if different from the real name.
soname_spec="\${libname}\${release}\${shared_ext}\$major"

# Commands used to build and install an old-style archive.
RANLIB="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-ranlib"
old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$oldlib"
old_postinstall_cmds="chmod 644 \$oldlib~\$RANLIB \$oldlib"
old_postuninstall_cmds=""

# Create an old-style archive from a shared archive.
old_archive_from_new_cmds=""

# Create a temporary old-style archive to link instead of a shared
archive. old_archive_from_expsyms_cmds=""

# Commands used to build and install a shared archive.
archive_cmds="\$CC -shared \$libobjs \$deplibs \$compiler_flags
\${wl}-soname \$wl\$soname -o \$lib" archive_expsym_cmds="\$echo
\\\"{ global:\\\" > \$output_objdir/\$libname.ver~ cat \$export_symbols
| sed -e \\\"s/\\\\(.*\\\\)/\\\\1;/\\\" >>
\$output_objdir/\$libname.ver~ \$echo \\\"local: *; };\\\" >>
\$output_objdir/\$libname.ver~ \$CC -shared \$libobjs \$deplibs
\$compiler_flags \${wl}-soname \$wl\$soname \${wl}-version-script
\${wl}\$output_objdir/\$libname.ver -o \$lib" postinstall_cmds=""
postuninstall_cmds=""

# Commands used to build a loadable module (assumed same as above if
empty) module_cmds=""
module_expsym_cmds=""

# Commands to strip libraries.
old_striplib="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-strip
--strip-debug"
striplib="/opt/timesys/toolchains/ppc86xx-linux/bin/ppc86xx-linux-strip
--strip-unneeded"

# Dependencies to place before the objects being linked to create a
# shared library.
predep_objects=""

# Dependencies to place after the objects being linked to create a
# shared library.
postdep_objects=""

# Dependencies to place before the objects being linked to create a
# shared library.
predeps=""

# Dependencies to place after the objects being linked to create a
# shared library.
postdeps=""

# The library search path used internally by the compiler when linking
# a shared library.
compiler_lib_search_path=""

# Method to check whether dependent libraries are shared objects.
deplibs_check_method="pass_all"

# Command to use when deplibs_check_method == file_magic.
file_magic_cmd="\$MAGIC_CMD"

# Flag that allows shared libraries with undefined symbols to be built.
allow_undefined_flag=""

# Flag that forces no undefined symbols.
no_undefined_flag=""

# Commands used to finish a libtool library installation in a directory.
finish_cmds="PATH=\\\"\\\$PATH:/sbin\\\" ldconfig -n \$libdir"

# Same as above, but a single script fragment to be evaled but not
shown. finish_eval=""

# Take the output of nm and produce a listing of raw symbols and C
names. global_symbol_pipe="sed -n -e
's/^.*[ 	]\\([ABCDGIRSTW][ABCDGIRSTW]*\\)[ 	][ 	]*\\([_A-Za-z][_A-Za-z0-9]*\\)\$/\\1
\\2 \\2/p'"

# Transform the output of nm in a proper C declaration
global_symbol_to_cdecl="sed -n -e 's/^. .* \\(.*\\)\$/extern int
\\1;/p'"

# Transform the output of nm in a C name address pair
global_symbol_to_c_name_address="sed -n -e 's/^: \\([^ ]*\\) \$/
{\\\"\\1\\\", (lt_ptr) 0},/p' -e 's/^[BCDEGRST] \\([^ ]*\\)
\\([^ ]*\\)\$/  {\"\\2\", (lt_ptr) \\&\\2},/p'"

# This is the shared library runtime path variable.
runpath_var=LD_RUN_PATH

# This is the shared library path variable.
shlibpath_var=LD_LIBRARY_PATH

# Is shlibpath searched before the hard-coded library search path?
shlibpath_overrides_runpath=no

# How to hardcode a shared library path into an executable.
hardcode_action=immediate

# Whether we should hardcode library paths into libraries.
hardcode_into_libs=yes

# Flag to hardcode $libdir into a binary during linking.
# This must work even if $libdir does not exist.
hardcode_libdir_flag_spec="\${wl}--rpath \${wl}\$libdir"

# If ld is used when linking, flag to hardcode $libdir into
# a binary during linking. This must work even if $libdir does
# not exist.
hardcode_libdir_flag_spec_ld=""

# Whether we need a single -rpath flag with a separated argument.
hardcode_libdir_separator=""

# Set to yes if using DIR/libNAME during linking hardcodes DIR into the
# resulting binary.
hardcode_direct=no

# Set to yes if using the -LDIR flag during linking hardcodes DIR into
the # resulting binary.
hardcode_minus_L=no

# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
into # the resulting binary.
hardcode_shlibpath_var=unsupported

# Set to yes if building a shared library automatically hardcodes DIR
into the library # and all subsequent libraries and executables linked
against it. hardcode_automatic=no

# Variables whose values should be saved in libtool wrapper scripts and
# restored at relink time.
variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH
GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"

# Whether libtool must link a program against all its dependency
libraries. link_all_deplibs=unknown

# Compile-time system search path for libraries
sys_lib_search_path_spec="/opt/timesys/toolchains/lib/gcc/powerpc-timesys-linux-gnu/4.2.1/74xx /opt/timesys/toolchains/powerpc-timesys-linux-gnu/lib/74xx /opt/timesys/toolchains/lib/gcc/powerpc-timesys-linux-gnu/4.2.1 /opt/timesys/toolchains/powerpc-timesys-linux-gnu/lib /opt/timesys/toolchains/powerpc-timesys-linux-gnu/libc/74xx/lib /opt/timesys/toolchains/powerpc-timesys-linux-gnu/libc/74xx/usr/lib"

# Run-time system search path for libraries
sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/qt-3.3/lib /usr/lib64/qt-3.3/lib
"

# Fix the shell variable $srcfile for the compiler.
fix_srcfile_path=""

# Set to yes if exported symbols are required.
always_export_symbols=no

# The commands to list exported symbols.
export_symbols_cmds="\$NM \$libobjs \$convenience |
\$global_symbol_pipe | \$SED 's/.* //' | sort | uniq > \$export_symbols"

# The commands to extract the exported symbol list from a shared
archive. extract_expsyms_cmds=""

# Symbols that should not be listed in the preloaded symbols.
exclude_expsyms="_GLOBAL_OFFSET_TABLE_"

# Symbols that must always be exported.
include_expsyms=""