We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1429 - Compiling static library with -arch fails when linking showimage
Summary: Compiling static library with -arch fails when linking showimage
Status: RESOLVED FIXED
Alias: None
Product: SDL_image
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.12
Hardware: x86_64 Mac OS X (All)
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-23 10:48 UTC by Gabriel Jacobo
Modified: 2012-02-28 18:59 UTC (History)
0 users

See Also:


Attachments
Fix for sdl2-config line for static libs under OSX (799 bytes, patch)
2012-02-24 04:26 UTC, Gabriel Jacobo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Jacobo 2012-02-23 10:48:46 UTC
This happens at least in Lion, with CFLAGS="-arch i386" or CFLAGS="-arch x86_64"
The workaround I'm using is removing showimage from the Makefile


i386:

/bin/sh ./libtool --tag=CC   --mode=link gcc  -I/Users/gabo/ignifuga/dist/osx/include/libpng12 -g -O2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -I/Users/gabo/ignifuga/dist/osx/include/SDL2 -D_THREAD_SAFE   -o showimage showimage.o libSDL2_image.la -L/Users/gabo/ignifuga/dist/osx/lib /Users/gabo/ignifuga/dist/osx/lib/libSDL2.a -lm -liconv -Wl,-framework,OpenGL -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit
libtool: link: gcc -I/Users/gabo/ignifuga/dist/osx/include/libpng12 -g -O2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -I/Users/gabo/ignifuga/dist/osx/include/SDL2 -D_THREAD_SAFE -o showimage showimage.o -Wl,-framework -Wl,OpenGL -Wl,-framework -Wl,ForceFeedback -Wl,-framework -Wl,Cocoa -Wl,-framework -Wl,Carbon -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreAudio -Wl,-framework -Wl,AudioToolbox -Wl,-framework -Wl,AudioUnit  ./.libs/libSDL2_image.a -L/Users/gabo/ignifuga/dist/osx/lib /Users/gabo/ignifuga/dist/osx/lib/libSDL2.a -lm -liconv -lobjc
ld: warning: ignoring file ./.libs/libSDL2_image.a, file was built for archive which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
  "_IMG_LoadTexture", referenced from:
      _main in showimage.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [showimage] Error 1


x86_64:

/bin/sh ./libtool --tag=CC   --mode=link gcc  -I/opt/local/include/libpng14   -g -O2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64 -I/Users/gabo/ignifuga/dist/osx/include/SDL2 -D_THREAD_SAFE  -static-libgcc -o showimage showimage.o libSDL2_image.la -L/Users/gabo/ignifuga/dist/osx/lib /Users/gabo/ignifuga/dist/osx/lib/libSDL2.a -lm -liconv -Wl,-framework,OpenGL -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit
libtool: link: gcc -I/opt/local/include/libpng14 -g -O2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64 -I/Users/gabo/ignifuga/dist/osx/include/SDL2 -D_THREAD_SAFE -static-libgcc -o showimage showimage.o -Wl,-framework -Wl,OpenGL -Wl,-framework -Wl,ForceFeedback -Wl,-framework -Wl,Cocoa -Wl,-framework -Wl,Carbon -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreAudio -Wl,-framework -Wl,AudioToolbox -Wl,-framework -Wl,AudioUnit  ./.libs/libSDL2_image.a -L/Users/gabo/ignifuga/dist/osx/lib /Users/gabo/ignifuga/dist/osx/lib/libSDL2.a -lm -liconv -lobjc
ld: warning: ignoring file ./.libs/libSDL2_image.a, file was built for archive which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "_IMG_LoadTexture", referenced from:
      _main in showimage.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [showimage] Error 1
Comment 1 Gabriel Jacobo 2012-02-23 19:37:16 UTC
I'm seeing this in SDL_image's showimage as well as in my own projects...I think I've managed to reduce the problem to the sdl2-config --libs line, that gives me:

-L/Users/gabo/ignifuga/dist/osx32/lib /Users/gabo/ignifuga/dist/osx32/lib/libSDL2.a -lm -liconv -Wl,-framework,OpenGL -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit

Note that instead of -lSDL2 it's giving out the full path without -l, so it will be statically linked!

This in turns makes the static library generation for SDL_ttf (and SDL_image) look something like:

libtool: link: ar cru .libs/libSDL2_ttf.a /Users/gabo/ignifuga/dist/osx32/lib/libSDL2.a  SDL_ttf.o

So, instead of only archiving SDL_ttf.o it's trying to archive libSDL2.a as well...THIS is the actual problem...removing libSDL2.a by hand from the Makefile solves the issue...

However, if I apply the fix in sdl2-config (changing /Users/gabo/ignifuga/dist/osx32/lib/libSDL2.a by -lSDL2), the configure script for SDL_image halts at "checking for SDL - version >= 2.0.0..."
Comment 2 Gabriel Jacobo 2012-02-24 04:26:53 UTC
Created attachment 827 [details]
Fix for sdl2-config line for static libs under OSX

Sorry for the brain fart yesterday, it turns out that sleeping on a problem is always a good idea. Anyway, replacing the whole library path for -lSDL2 actually solves the problem, so this patch should solve the issue. SDL_ttf and SDL_image compile statically without issue now.
Comment 3 Sam Lantinga 2012-02-28 18:59:18 UTC
I don't think we need that hack anymore, thanks!
http://hg.libsdl.org/SDL/rev/6bb657898f55