libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mac OS X static linking (ranlib) fix


From: Don Anderson
Subject: Mac OS X static linking (ranlib) fix
Date: Sat, 13 Jul 2002 15:15:15 -0400 (EDT)

Libtoolers,

We encountered a difference in ranlib behavior on Mac OS X that caused
a linking error.  By default, Mac OS X ranlib does not put common
symbols in the index.  Thus, common symbols that appear in a .o in
static library that are not referred to from the main program, but are
referred to from within a different library .o module are not
included.  That's a mouthful, here's an example that shows the difference:

================> prog.c <================
extern void l1();
main()
{
  printf("hello");
  l1();
}

================> l1.c <================
extern int l2;
void l1()
{
  printf("l1 %d\n", l2);
}

================> l2.c <================
int l2;
l2_func()
{
  l2 = 77;
}

================> Makefile <================
all:  prog

prog: prog.o lib.a
        cc -o prog prog.o lib.a

lib.a: l1.o l2.o
        ar rv lib.a l1.o l2.o
================================================

This will produce a unresolved symbol l2 when you link this on Mac OS
X, but not unresolved anywhere (?) else.  They have a ranlib option -c
that gives the compatible behavior.  We worked around this by changing
our source, but I thought you all should know.

I've attached a patch that should fix it.  BTW, line 185 in libtool.m4:

  if test -n "$RANLIB"; then

Looks like it will always be true because of a previous line:

  test -z "$RANLIB" && RANLIB=:


Thanks,

Don Anderson


Index: ChangeLog
===================================================================
RCS file: /cvsroot/libtool/libtool/ChangeLog,v
retrieving revision 1.1125
diff -c -r1.1125 ChangeLog
*** ChangeLog   26 Jun 2002 07:15:36 -0000      1.1125
--- ChangeLog   13 Jul 2002 19:00:55 -0000
***************
*** 1,3 ****
--- 1,7 ----
+ 2002-07-13  Donald Anderson  <address@hidden>
+ 
+       * libtool.m4 (darwin): use ranlib -c for full compatibility.
+ 
  2002-06-26  Bob Friesenhahn  <address@hidden>
  
        * libtool.m4 (AC_LIBTOOL_SYS_DYNAMIC_LINKER) [mingw]: Remove
Index: libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/libtool.m4,v
retrieving revision 1.261
diff -c -r1.261 libtool.m4
*** libtool.m4  26 Jun 2002 07:15:36 -0000      1.261
--- libtool.m4  13 Jul 2002 19:01:00 -0000
***************
*** 184,197 ****
  
  if test -n "$RANLIB"; then
    case $host_os in
    openbsd*)
!     old_postinstall_cmds="\$RANLIB -t \$oldlib~$old_postinstall_cmds"
      ;;
    *)
!     old_postinstall_cmds="\$RANLIB \$oldlib~$old_postinstall_cmds"
      ;;
    esac
!   old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
  fi
  
  # Only perform the check for file, if the check method requires it
--- 184,203 ----
  
  if test -n "$RANLIB"; then
    case $host_os in
+   darwin* | rhapsody*)
+     ranlib_archive_cmd="\$RANLIB -c \$oldlib"
+     ranlib_postinstall_cmd="\$RANLIB -c \$oldlib"
+     ;;
    openbsd*)
!     ranlib_postinstall_cmd="\$RANLIB -t \$oldlib"
      ;;
    *)
!     ranlib_archive_cmd="\$RANLIB \$oldlib"
!     ranlib_postinstall_cmd="\$RANLIB \$oldlib"
      ;;
    esac
!   old_archive_cmds="$old_archive_cmds~$ranlib_archive_cmd"
!   old_postinstall_cmds="$ranlib_postinstall_cmd~$old_postinstall_cmds"
  fi
  
  # Only perform the check for file, if the check method requires it

-- 

        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        Remember to send requests for assistance on
        new problems to address@hidden
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        Don Anderson                    address@hidden
        Sleepycat Software Inc.         +1-978-287-4781
        118 Tower Rd.                   http://www.sleepycat.com
        Lincoln, MA 01773




reply via email to

[Prev in Thread] Current Thread [Next in Thread]