• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Maxjen

link libSDL2.a with cmake

5 posts in this topic

Hi,

 

I'm trying to compile a simple SDL2 application with cmake under Linux. My CMakeLists.txt looks like this:

project(Test)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)

find_package(OpenGL)

add_executable(${PROJECT_NAME} ${SRC_LIST})

#target_link_libraries(${PROJECT_NAME} /usr/local/lib/libSDL2.so ${OPENGL_gl_LIBRARY})
target_link_libraries(${PROJECT_NAME} /usr/local/lib/libSDL2.a pthread dl rt ${OPENGL_gl_LIBRARY})

It works immediately if I link it to libSDL2.so, but if I link it to libSDL2.a I have to add pthread, dl and rt or it gives me undefined reference errors like /usr/bin/ld: /usr/local/lib/libSDL2.a(SDL_syssem.o): undefined reference to symbol 'sem_getvalue@@GLIBC_2.2.5'. Can somebody explain why this is?

And is it correct that if I link my application to libSDL2.a that I can execute the binary file on any Linux installation without requiring SDL2 to be installed?

0

Share this post


Link to post
Share on other sites

Hi,

 

Basically the '.a' file is a static link library, meaning it pretty much only contains an archive of the SDL '.o' object files.

The '.so' file is a shared library meaning that it drags in its other dependent libraries as required at runtime.

 

If you do an 'ldd libSDL2.so', you will see that it lists all the SDL dependencies such as pthread etc...

 

However, if using Linux (rather than *BSD), you should usually explicitly specify linked dependencies even though the .so file already has them due to DSO linking changes in newer Linux distros. (http://fedoraproject.org/wiki/UnderstandingDSOLinkChange)

 

And, yes, if you statically link "everything" into your binary, it should mean that you can take it across to other Linux distros without having to get your players to install packages. Otherwise you would need to also carry across the .so files and set the LD_LIBRARY_PATH or something for your application to use them.

Linux is always in such a state of flux though that this isn't always guaranteed to work however, if the version of libc differ for example. Unfortunately certain libc versions also require an older or newer version of the Linux kernel.

Again, do a 'ldd' of your output application to see exactly what external libraries it depends on.

Edited by Karsten_
1

Share this post


Link to post
Share on other sites

Thanks, that was very helpful!

 

I did ldd libSDL2.so and it listed these dependencies.

$ ldd libSDL2.so
    linux-vdso.so.1 =>  (0x00007fff507fe000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fa64d693000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fa64d48f000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa64d272000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fa64d06a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fa64ccb2000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003b9b400000)

However, I am still unsure if I have to add the dependencies that I haven't specified in my CMakeLists.txt so that it still works with those DSO linking changes. As mentioned I had to add libpthread, libdl, and librt. Must I now add libm, libc, linux-vdso and ld-linux-x86-64?
 

0

Share this post


Link to post
Share on other sites

Thanks, that was very helpful!

 

I did ldd libSDL2.so and it listed these dependencies.

$ ldd libSDL2.so
    linux-vdso.so.1 =>  (0x00007fff507fe000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fa64d693000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fa64d48f000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa64d272000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fa64d06a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fa64ccb2000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003b9b400000)

However, I am still unsure if I have to add the dependencies that I haven't specified in my CMakeLists.txt so that it still works with those DSO linking changes. As mentioned I had to add libpthread, libdl, and librt. Must I now add libm, libc, linux-vdso and ld-linux-x86-64?
 

If you want a purely static binary (no DSOs at all) then yes, you'd need to link all those libraries (save libc and the DSO interpreter, ld-linux-x86-64.so.2 and linux-vdso.so.1).  You would want to make sure you pass the relevant -static switches to the linker to get it to pick up the static versions of the runtime (libc).

 

I'd like to point out that you'll probably have trouble.  One of the dependencies is libdl, the dynamic library loader, which implies libSDL2 load plugins dynamically.  That will probably fail since there is no DSO interpreter to resolve the symbols at load time.  You're in for a world of pain, trying to do something the GNU system was designed explicitly to avoid.

1

Share this post


Link to post
Share on other sites

I think right now I am only linking libSDL2 statically. Will I still have trouble?

project(Test)
cmake_minimum_required(VERSION 2.8)

set(SRC_LIST main.cpp)

find_package(OpenGL)

#SDL2 plus dependencies
set(SDL2
    /usr/local/lib/libSDL2.a
    pthread
    dl
    rt
    m
)

include_directories("${PROJECT_SOURCE_DIR}/include/")

add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SDL2} ${OPENGL_gl_LIBRARY})

I would like to be able to for example send the binary file to friends so they can test it and I think it would be too much to ask them to install SDL2 because on most distributions it can't be easily installed with the package manager. But it would be perfectly fine to link everything else dynamically.

Edited by Maxjen
0

Share this post


Link to post
Share on other sites

If I recall correctly, there was a compile time option for SDL_image to either load in libpng.so dynamically at runtime or to statically compile in support (in which case zlib and libpng source files are also needed during compile time of the library). Perhaps there is a similar option in SDL2?

 

But yeah, it is a shame SDL2 is taking so long to reach the package repos / ports collections. I also find version 2 to be very poorly documented so I am staying away for a while longer ;)

Edited by Karsten_
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0