Compiling static libs with make?

I can produce and use static libraries for SDL2 on Windows, but I am unsure how to produce static libraries on linux or MacOSX. Is there an argument for configure or make that will build the static libraries?

The cmake alternative appears to produce a static library on linux, but it comes with a warning that it is experimental. I am also unclear about debug vs. release configurations with this option, as only one libSDL2.a is produced.

Please forgive if there is a standard/easy way to do these things on linux that I am unaware of. I am not an advanced linux user. I have tried to find descriptions of these things in the readme files and wiki but was unable.

Also, I should ask what does “make install” do? I am a bit leery of something that may make this SDL build part of the system rather than something I am simply statically linking in.

Use the “ar” command… Feed it a list of .o files, and it produces a .a
file.Sent from my Windows Phone

From: rainwarrior@rainwarrior.ca (rainwarrior)
Sent: 12/15/2013 5:38 PM
To: sdl at lists.libsdl.org
Subject: [SDL] Compiling static libs with make?

I can produce and use static libraries for SDL2 on Windows, but I am
unsure how to produce static libraries on linux or MacOSX. Is there an
argument for configure or make that will build the static libraries?

The cmake alternative appears to produce a static library on linux, but it
comes with a warning that it is experimental. I am also unclear about debug
vs. release configurations with this option, as only one libSDL2.a is
produced.

Please forgive if there is a standard/easy way to do these things on linux
that I am unaware of. I am not an advanced linux user. I have tried to find
descriptions of these things in the readme files and wiki but was unable.

Also, I should ask what does “make install” do? I am a bit leery of
something that may make this SDL build part of the system rather than
something I am simply statically linking in.

subatomic wrote:

Use the “ar” command… Feed it a list of .o files, and it produces a .a file.

That’s not the question I’m asking; I do not have a set of .o files already built with the proper configuration for the static library.

I’m asking for the correct method to build the static SDL2 library on linux.

I can produce and use static libraries for SDL2 on Windows, but I am unsure how
to produce static libraries on linux or MacOSX. Is there an argument for
configure or make that will build the static libraries?

Yes, --disable-shared, as

./configure --disable-shared

The cmake alternative appears to produce a static library on linux, but it comes
with a warning that it is experimental. I am also unclear about debug vs.
release configurations with this option, as only one libSDL2.a is produced.

On Linux, debug and release builds are compatible (almost always). It is common
to build with optimizations and debugging enabled in the same build (-O2 -g).
Since you can link debug and non-debug binaries together, it’s not necessary to
maintain separate build hierarchies as developers might do on Windows. You can
strip the final binary to discard debugging symbols before you deploy it.

If you want to maintain separate builds for debug and release, the simplest
thing to do is build/install everything twice, with different --prefix options.
Maintain a debug/ tree and a release/ tree.

Please forgive if there is a standard/easy way to do these things on linux that
I am unaware of. I am not an advanced linux user. I have tried to find
descriptions of these things in the readme files and wiki but was unable.

Also, I should ask what does “make install” do? I am a bit leery of something
that may make this SDL build part of the system rather than something I am
simply statically linking in.

You are wise to be leery. make install copies the library, headers, and docs
to a system-wide directory. You should instead create a dir for your builds,
such as $HOME/devel/ and specify it with the --prefix option, as

./configure --disable-shared --prefix=$HOME/devel/On 12/15/2013 06:38 PM, rainwarrior wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Both static and dynamic builds are enabled by default when you use
configure. You can force it with the --enable-static option to
configure, shouldn’t be necessary though. (Run ./configure --help to get
a list of all the options you can use. There’s a lot!)

“make install” installs everything you need to use SDL to… some
location. It defaults to /usr/local (on linux, anyway), but you can
change that with the --prefix option to configure. Like this:

./configure --prefix=/path/you/want

It doesn’t really matter what path you choose, just pick somewhere
that’s convenient for you =). Use the installed bin/sdl2-config script
to get options for the compiler/linker when using SDL in your programs
(symlink sdl2-config to a dir in your path for extra convenience, if it
isn’t already). Pass it --cflags to get include path and such, --libs
for dynamic libs, and… in theory, --static-libs for static ones,
although that doesn’t seem to actually do the right thing now that I
look at it, unless you already link everything statically, which you
probably don’t want. You can just add ‘/path-you-chose/lib/libSDL2.a’ to
your link line though.

Btw, if you’re building executables for distribution, you probably want
to disable embedding the local SDL’s rpath in your executable (rpath
adds to the runtime linker’s default library search path). It’s set by
sdl2-config’s --libs and --static-libs by default. Disable that with
–disable-rpath to configure (or just edit the installed sdl2-config).
rpath is useful when testing dynamically linked builds locally, but for
distribution you’ll want to customize that so it finds your
also-distributed libs (either via rpath or LD_LIBRARY_PATH)

Also, it can be useful to run configure from a different directory than
the one it resides in. Make a build directory for it: mkdir build; cd
build; …/configure [options]. It keeps generated files contained, makes
it possible to keep multiple builds around, etc. You’ll have to copy the
test dir to your build dir if you want the tests to work though.

-g

Den 16. des. 2013 00:38, skrev rainwarrior:> I can produce and use static libraries for SDL2 on Windows, but I am

unsure how to produce static libraries on linux or MacOSX. Is there
an argument for configure or make that will build the static
libraries?

The cmake alternative appears to produce a static library on linux,
but it comes with a warning that it is experimental. I am also
unclear about debug vs. release configurations with this option, as
only one libSDL2.a is produced.

Please forgive if there is a standard/easy way to do these things on
linux that I am unaware of. I am not an advanced linux user. I have
tried to find descriptions of these things in the readme files and
wiki but was unable.

Also, I should ask what does “make install” do? I am a bit leery of
something that may make this SDL build part of the system rather than
something I am simply statically linking in.

_______________________________________________ SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

OK, I have now tried configure --enable-static but the results seem that same as before. After running make a /build folder is produced, but the only libraries that result are libSDL2main.a and libSDL2_test.a. Am I missing something?

Alternatively configure --disable-shared has the same result.

Ah, it is put together by make install, this is the part I was confused about.

Thanks everyone for your help, especially the bit about the prefix to put the install somewhere specific.