MacOS and static linking problem

Hi,

I’m attempting to make a nice redistributable version of TyrQuake
using command line tools and running into a problem with static
linking. The build command looks like this:

cc -o Launcher foo.o bar.o … -arch x86_64 -static sdl2-config --static-libs

And sdl2-config --static-libs evalutes to:

-L/usr/local/lib -lSDL2 -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

And the result is:

ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Launcher] Error 1

OSX version 10.8.3, xcode version 4.6.1.

Using current source from hg;
$ hg summary
parent: 7027:b1c25fd3907f tip
Added support for the GameStop Gamepad

Nothing fancy with the build, just ./configure && make && sudo make
install. I still call myself a Mac newbie, so it could just be
something simple. Does this look like a familiar problem to anyone?

Thanks,
Kevin.

cc -o Launcher foo.o bar.o … -arch x86_64 -static sdl2-config --static-libs

You should remove for sure -static from your command line, otherwise GCC
will try to find a static library for everything, also system frameworks,
and,…

And sdl2-config --static-libs evalutes to:

-L/usr/local/lib -lSDL2 -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

…as far as I can see from your --static-libs, except if you have build
SDL as static only with --disable-shared, the output of sdl-config is
wrong, it should contain something like:

[…] -Wl,"-Bstatic" -lSDL2 -Wl,"-Bdynamic" […]

Anyway usually there is no need to compile statically on OSX, since you can
distribute SDL as framework inside your application bundle.–
Bye,
Gabry

cc -o Launcher foo.o bar.o … -arch x86_64 -static sdl2-config --static-libs

You should remove for sure -static from your command line, otherwise GCC
will try to find a static library for everything, also system frameworks,
and,…

Ok, will do. I added that later when I realised that SDL was still
being linked dynamically. That was the only option I could find. And
I thought it wasn’t right when the the man page said ‘Only used
building the kernel’. :slight_smile:

And sdl2-config --static-libs evalutes to:

-L/usr/local/lib -lSDL2 -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

…as far as I can see from your --static-libs, except if you have build
SDL as static only with --disable-shared, the output of sdl-config is
wrong, it should contain something like:

[…] -Wl,"-Bstatic" -lSDL2 -Wl,"-Bdynamic" […]

It seems -Bstatic is no longer a recognised linker option:

ld: unknown option: -Bstatic

Anyway usually there is no need to compile statically on OSX, since you can
distribute SDL as framework inside your application bundle.

Thanks, I will look into this option.

Cheers,
Kevin.On Tue, Mar 26, 2013 at 05:48:25PM +0100, Gabriele Greco wrote: