Fixed bug 938 - SDL fails to link in mingw+msys+libtool SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 14:14:45 -0500
branchSDL-1.2
changeset 6130987c365cc7bf
parent 6129 19c7412a6345
child 6131 804c6c62c55f
Fixed bug 938 - SDL fails to link in mingw+msys+libtool

Carlo Bramini 2010-01-27 10:06:17 PST
When building third party software powered by libtool (like xine-lib and
several others) under Mingw+MSys, libSDL fails to link.
I got this message when building SDL video out component of xine-lib:

*** Warning: linker path does not have real file for library -lmingw32.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libmingw32 and none of the candidates passed a file format test
*** using a file magic. Last file checked: /mingw/lib/libmingw32.a

Apparently there is no need to manually add -lmingw32 for making libSDL
working.
If this flag is removed, everything is built without troubles.
If it has been added for fixing a cross-compiler, perhaps if would be a better
idea to adjust its SPECS file in the same manner it has been done in the true
one used by mingw on Windows (I'm just guessing why it exists here).

There is also another message received on the console:

*** Warning: linker path does not have real file for library -lSDLmain.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libSDLmain and none of the candidates passed a file format test
*** using a file magic. Last file checked: /mingw/lib/libSDLmain.a

This message, like previous one, is caused by -no-undefined flag sent to
libtool when building shared libraries.
Actually adding an .la file with its dependencies solves the troubles, so I
believe it would be better to create it too in the build process of libSDL.
Makefile.in
SDL.qpg.in
build-scripts/makedep.sh
configure.in
     1.1 --- a/Makefile.in	Fri Dec 30 06:54:58 2011 -0500
     1.2 +++ b/Makefile.in	Fri Dec 30 14:14:45 2011 -0500
     1.3 @@ -36,9 +36,10 @@
     1.4  SOURCES = @SOURCES@
     1.5  OBJECTS = @OBJECTS@
     1.6  
     1.7 -SDLMAIN_TARGET = libSDLmain.a
     1.8 +SDLMAIN_TARGET = libSDLmain.la
     1.9  SDLMAIN_SOURCES = @SDLMAIN_SOURCES@
    1.10  SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
    1.11 +SDLMAIN_LDFLAGS = @SDLMAIN_LDFLAGS@
    1.12  
    1.13  DIST = acinclude autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE VisualC.html VisualC Watcom-OS2.zip Watcom-Win32.zip symbian.zip WhatsNew Xcode
    1.14  
    1.15 @@ -65,22 +66,17 @@
    1.16  
    1.17  .PHONY: all depend install install-bin install-hdrs install-lib install-data install-man uninstall uninstall-bin uninstall-hdrs uninstall-lib uninstall-data uninstall-man clean distclean dist
    1.18  depend:
    1.19 -	@SOURCES="$(SOURCES)" INCLUDE="$(INCLUDE)" output="$(depend)" \
    1.20 +	@SOURCES="$(SOURCES) $(SDLMAIN_SOURCES)" INCLUDE="$(INCLUDE)" output="$(depend)" \
    1.21  	$(SHELL) $(auxdir)/makedep.sh
    1.22 -	@for src in $(SDLMAIN_SOURCES); do \
    1.23 -	    obj=`echo $$src | sed -e 's|.*/||' -e 's|\.[^\.]*$$|.o|'`; \
    1.24 -	    echo "\$$(objects)/$$obj: $$src" >>$(depend); \
    1.25 -	    echo "	\$$(CC) \$$(CFLAGS) \$$(EXTRA_CFLAGS) -c $$src -o \$$@" >>$(depend); \
    1.26 -	done
    1.27  
    1.28  include $(depend)
    1.29  
    1.30  $(objects)/$(TARGET): $(OBJECTS)
    1.31 -	$(LIBTOOL) --mode=link $(CC) -o $@ $(OBJECTS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS)
    1.32 +	$(LIBTOOL) --mode=link $(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS)
    1.33  
    1.34  $(objects)/$(SDLMAIN_TARGET): $(SDLMAIN_OBJECTS)
    1.35 -	$(AR) cru $@ $(SDLMAIN_OBJECTS)
    1.36 -	$(RANLIB) $@
    1.37 +	$(LIBTOOL) --mode=link $(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS) $(SDLMAIN_LDFLAGS)
    1.38 +
    1.39  
    1.40  install: all install-bin install-hdrs install-lib install-data install-man
    1.41  install-bin:
    1.42 @@ -95,8 +91,7 @@
    1.43  install-lib: $(objects) $(objects)/$(TARGET) $(objects)/$(SDLMAIN_TARGET)
    1.44  	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)
    1.45  	$(LIBTOOL) --mode=install $(INSTALL) $(objects)/$(TARGET) $(DESTDIR)$(libdir)/$(TARGET)
    1.46 -	$(INSTALL) -m 644 $(objects)/$(SDLMAIN_TARGET) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
    1.47 -	$(RANLIB) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
    1.48 +	$(LIBTOOL) --mode=install $(INSTALL) $(objects)/$(SDLMAIN_TARGET) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
    1.49  install-data:
    1.50  	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(datadir)/aclocal
    1.51  	$(INSTALL) -m 644 $(srcdir)/sdl.m4 $(DESTDIR)$(datadir)/aclocal/sdl.m4
    1.52 @@ -120,7 +115,7 @@
    1.53  	-rmdir $(DESTDIR)$(includedir)/SDL
    1.54  uninstall-lib:
    1.55  	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(TARGET)
    1.56 -	rm -f $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
    1.57 +	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
    1.58  uninstall-data:
    1.59  	rm -f $(DESTDIR)$(datadir)/aclocal/sdl.m4
    1.60  	rm -f $(DESTDIR)$(libdir)/pkgconfig/sdl.pc
     2.1 --- a/SDL.qpg.in	Fri Dec 30 06:54:58 2011 -0500
     2.2 +++ b/SDL.qpg.in	Fri Dec 30 14:14:45 2011 -0500
     2.3 @@ -28,7 +28,8 @@
     2.4           <QPG:Add filetype="symlink" file="libSDL.so" install="/usr/lib/" linkto="libSDL-@SDL_MAJOR_VERSION@.@SDL_MINOR_VERSION@.so.@LT_AGE@"/>
     2.5           <QPG:Add permissions="0644" file="./src/.libs/libSDL.a" install="/usr/lib/"/>
     2.6           <QPG:Add permissions="0644" file="./src/.libs/libSDL.lai" install="/usr/lib/libSDL.la"/>
     2.7 -         <QPG:Add permissions="0644" file="./src/main/libSDLmain.a" install="/usr/lib/"/>
     2.8 +         <QPG:Add permissions="0644" file="./src/.libs/libSDLmain.a" install="/usr/lib/"/>
     2.9 +         <QPG:Add permissions="0644" file="./src/.libs/libSDLmain.lai" install="/usr/lib/libSDLmain.lai"/>
    2.10           <QPG:Add permissions="0644" file="./include/*.h" install="/usr/include/SDL/"/>
    2.11           <QPG:Add permissions="0755" file="./sdl-config" install="/usr/bin/"/>
    2.12           <QPG:Add permissions="0644" file="./BUGS" install="/usr/share/doc/SDL12/"/>
     3.1 --- a/build-scripts/makedep.sh	Fri Dec 30 06:54:58 2011 -0500
     3.2 +++ b/build-scripts/makedep.sh	Fri Dec 30 14:14:45 2011 -0500
     3.3 @@ -41,13 +41,13 @@
     3.4  for src in $SOURCES
     3.5  do  echo "Generating dependencies for $src"
     3.6      ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
     3.7 -    if test x"$ext" = x"rc"; then
     3.8 -        obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.o|g"`
     3.9 -    else
    3.10 -        obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
    3.11 +    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
    3.12 +    echo "\$(objects)/$obj: $src \\" >>${output}.new
    3.13 +
    3.14 +    # No search to be done with Windows resource files
    3.15 +    if test x"$ext" != x"rc"; then
    3.16 +        search_deps $src | sort | uniq >>${output}.new
    3.17      fi
    3.18 -    echo "\$(objects)/$obj: $src \\" >>${output}.new
    3.19 -    search_deps $src | sort | uniq >>${output}.new
    3.20      case $ext in
    3.21          c) cat >>${output}.new <<__EOF__
    3.22  
    3.23 @@ -81,7 +81,7 @@
    3.24          ;;
    3.25          rc) cat >>${output}.new <<__EOF__
    3.26  
    3.27 -	\$(WINDRES) $src \$@
    3.28 +	\$(LIBTOOL)  --tag=RC --mode=compile \$(WINDRES) $src -o \$@
    3.29  
    3.30  __EOF__
    3.31          ;;
     4.1 --- a/configure.in	Fri Dec 30 06:54:58 2011 -0500
     4.2 +++ b/configure.in	Fri Dec 30 14:14:45 2011 -0500
     4.3 @@ -1556,6 +1556,7 @@
     4.4              AC_DEFINE(SDL_VIDEO_DRIVER_QTOPIA)
     4.5              SOURCES="$SOURCES $srcdir/src/video/qtopia/*.cc"
     4.6              SDLMAIN_SOURCES="$srcdir/src/main/qtopia/*.cc"
     4.7 +            SDLMAIN_LDFLAGS="-static"
     4.8              EXTRA_CFLAGS="$EXTRA_CFLAGS $QTOPIA_FLAGS"
     4.9              SDL_CFLAGS="$SDL_CFLAGS -DQWS -Dmain=SDL_main"
    4.10              SDL_LIBS="-lSDLmain $SDL_LIBS -L${QPEDIR}/lib -L${QTDIR}/lib/ -lqpe -lqte"
    4.11 @@ -2548,8 +2549,9 @@
    4.12          # The Win32 platform requires special setup
    4.13          SOURCES="$SOURCES $srcdir/src/main/win32/*.rc"
    4.14          SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
    4.15 +        SDLMAIN_LDFLAGS="-static"
    4.16          SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
    4.17 -        SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows"
    4.18 +        SDL_LIBS="-lSDLmain $SDL_LIBS -mwindows"
    4.19          ;;
    4.20      *-wince*)
    4.21          ARCH=win32
    4.22 @@ -2591,6 +2593,7 @@
    4.23          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
    4.24          # The Win32 platform requires special setup
    4.25          SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
    4.26 +        SDLMAIN_LDFLAGS="-static"
    4.27          SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
    4.28          SDL_LIBS="-lSDLmain $SDL_LIBS"
    4.29          ;;
    4.30 @@ -2722,6 +2725,7 @@
    4.31          fi
    4.32          # The Mac OS X platform requires special setup.
    4.33          SDLMAIN_SOURCES="$srcdir/src/main/macosx/*.m"
    4.34 +        SDLMAIN_LDFLAGS="-static"
    4.35          EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings"
    4.36          SDL_LIBS="-lSDLmain $SDL_LIBS"
    4.37          if test x$enable_video_cocoa = xyes; then
    4.38 @@ -2858,6 +2862,7 @@
    4.39  fi
    4.40  if test x$SDLMAIN_SOURCES = x; then
    4.41      SDLMAIN_SOURCES="$srcdir/src/main/dummy/*.c"
    4.42 +    SDLMAIN_LDFLAGS="-static"
    4.43  fi
    4.44  
    4.45  OBJECTS=`echo $SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.asm,$(objects)/\1.lo,g'`
    4.46 @@ -2865,11 +2870,11 @@
    4.47  OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.lo,g'`
    4.48  OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
    4.49  OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.S,$(objects)/\1.lo,g'`
    4.50 -OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.rc,$(objects)/\1.o,g'`
    4.51 +OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.rc,$(objects)/\1.lo,g'`
    4.52  
    4.53 -SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.o,g'`
    4.54 -SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.o,g'`
    4.55 -SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.o,g'`
    4.56 +SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.lo,g'`
    4.57 +SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.lo,g'`
    4.58 +SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
    4.59  
    4.60  # Set runtime shared library paths as needed
    4.61  
    4.62 @@ -2931,6 +2936,7 @@
    4.63  AC_SUBST(OBJECTS)
    4.64  AC_SUBST(SDLMAIN_SOURCES)
    4.65  AC_SUBST(SDLMAIN_OBJECTS)
    4.66 +AC_SUBST(SDLMAIN_LDFLAGS)
    4.67  AC_SUBST(BUILD_CFLAGS)
    4.68  AC_SUBST(EXTRA_CFLAGS)
    4.69  AC_SUBST(BUILD_LDFLAGS)