Target_link_libraries Sdl Mac

Build SDL2 Demo using CMake for Android

Qt is certainly great, but there are other ways for creating cross-platform GUI, one of such ways being a combination of SDL and Dear ImGui. While, in my opinion, it barely can compete with Qt (especially Qt Quick) in terms of beauty and fancy, it is nevertheless a simple, lightweight and quite powerful “framework”. Sdl - SDLmain linking issues using CMake for Clion on OS X 2020腾讯云共同战“疫”,助力复工(优惠前所未有! 4核8G,5M带宽 1684元/3年),.



Joined: 06 Sep 2013
Posts: 12
Location: Berlin/Germany
Posted: Tue Nov 12, 2013 1:52 am
Hey, I need another help with SDL2 + CMake for Android. I almost got my cross-build demo working - Linux, Mac, iOS, and Windows are running, but Android is still somewhat draconian.
What works: A little test program based on the android-project within the SDL2 sources.
What I try: Build this same demo with CMake to simplify cross-platform development,
... but first I need to build SDL2 with CMake:
For that project I rely on the android-cmake toolchain, and its very outdated boost tutorial. Anyway, it works somehow and I only have to figure out the build process. Now, I try to apply it for my project, creating the CMakeLists.txt file based on the boost tutorial and modify it based on the Android.mk file inside the SDL package. This is my CMakeLists.txt so far:
Code:
cmake_minimum_required(VERSION 2.8)
project(SDL2)
set(SDL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/SDL)
include_directories(${SDL_ROOT}/include)
file (GLOB SOURCES
${SDL_ROOT}/src/*.c
# ...
${SDL_ROOT}/src/render/*/*.c
# ...
${SDL_ROOT}/src/test/*.c
)
add_library (SDL2 ${SOURCES})
target_link_libraries (SDL2 dl GLESv1_CM GLESv2 log android)

Looks to simple to work out of the box, and unfortunately it is true. The generation of the makefiles works, but the actual make process fails:
Code:
Scanning dependencies of target SDL2
[ 0%] Building C object CMakeFiles/SDL2.dir/SDL/src/SDL_hints.c.o
...
[ 35%] Building C object CMakeFiles/SDL2.dir/SDL/src/render/opengles/SDL_render_gles.c.o
In file included from /AndroidCMake/SDL/src/render/opengles/SDL_render_gles.c:203:0:
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h: In function 'GLES_LoadFunctions':
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:3:1: error: 'glBlendFuncSeparateOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:3:1: note: each undeclared identifier is reported only once for each function it appears in
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:11:1: error: 'glDrawTexfOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:15:1: error: 'glGenFramebuffersOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:33:1: error: 'glBindFramebufferOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:34:1: error: 'glFramebufferTexture2DOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:35:1: error: 'glCheckFramebufferStatusOES' undeclared (first use in this function)
/AndroidCMake/SDL/src/render/opengles/SDL_glesfuncs.h:40:1: error: 'glDeleteFramebuffersOES' undeclared (first use in this function)
make[2]: *** [CMakeFiles/SDL2.dir/SDL/src/render/opengles/SDL_render_gles.c.o] Error 1
make[1]: *** [CMakeFiles/SDL2.dir/all] Error 2
make: *** [all] Error 2

There's a similar thread on in this forum, but I don't get it. Btw. there's a confusing thread in the thread.
Okay, that's where I stuck. Any help is welcome to get it done, thanks.
Michael
Build SDL2 Demo using CMake for Android
Eric Wing

Posted: Tue Nov 12, 2013 3:37 am
On 11/11/13, Laz-Roc wrote:
Quote:
Hey, I need another help with SDL2 + CMake for Android. I almost got my
cross-build demo working - Linux, Mac, iOS, and Windows are running, but
Android is still somewhat draconian.
Okay, that's where I stuck. Any help is welcome to get it done, thanks.
Michael

Hi Michael,
This won't directly solve your problem, but will give you more
information on how to use Android-CMake, and more generally, the
Android NDK build chain, in non-trivial Android projects with
dependencies.
I have a sample repository for an Android Hello World program that
uses ALmixer. ALmixer uses CMake to build (consider it your SDL
proxy). I use my own fork of Android-CMake which contains fixes to use
the latest NDKs, as well as handle multiple architectures (arm, armv7,
x86).
(Note that this example compiles ALmixer without SDL dependencies and
instead uses a new experimental native Android OpenSL ES decoder
backend my team and I have been working on so it won't directly show
you how to deal with SDL.)
Additionally, OpenAL-Soft is a dependency that ALmixer depends on,
though this uses its own supplied Makefile system.
Once these components are built as dynamic libraries, the final Hello
World app build process relies on the official NDK module system to
find ALmixer and OpenAL and build appropriately.
All of this is strung together by some Perl scripts.
The README.txt contains a lot of information on how to setup things.
Android NDK development is really painful so take your time on this.
Don't expect to be able to grasp everything in 10 minutes.
The repository can be found at:
https://bitbucket.org/ewing/hello-android-almixer
Hope this helps,
Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Laz-Roc

Joined: 06 Sep 2013
Posts: 12
Location: Berlin/Germany
Posted: Wed Nov 13, 2013 1:30 am
Thanks Eric. Just got the sources and give it all a try the next days. And you are absolutely right, NDK is a pain. I really thought it couldn't be more worse than iOS, but I may be wrong. I'll report then.
Laz-Roc

Joined: 06 Sep 2013
Posts: 12
Location: Berlin/Germany
Posted: Sat Nov 23, 2013 6:58 pm
Have been away for awhile, but I'm back to tackle that Android + CMake problem again.
Well, I think I've been successful building a static SDL2 library with CMake, but wasn't able to build an app so I don't know if it's working. Vice versa, I couldn't build a static library with the provided SDL2 README, but a demo with a shared library.
I'd like to build a shared library, anyway. So I slightly modified my CMakeLists.txt to building a shared library by adding the SHARED tag.
Again, it creates the makefiles, and builds the object files. But I don't know how to solve the undefined reference error. Here are some of the errors (I stripped similar errors; here is the full error message):
Quote:

Linking C shared library ../libs/armeabi-v7a/libSDL2.so
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/SDL_assert.c.o: in function SDL_ReportAssertion:SDL_assert.c(.text.SDL_ReportAssertion+0x30): error: undefined reference to 'SDL_AtomicLock'
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/SDL_assert.c.o: in function SDL_ReportAssertion:SDL_assert.c(.text.SDL_ReportAssertion+0x80): error: undefined reference to 'SDL_AtomicUnlock'
/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/audio/SDL_audio.c.o: in function bootstrap:SDL_audio.c(.data.rel.ro.bootstrap+0x0): error: undefined reference to 'DUMMYAUD_bootstrap'
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/stdlib/SDL_stdlib.c.o: in function SDL_atan:SDL_stdlib.c(.text.SDL_atan+0x14): error: undefined reference to 'atan'
collect2: ld returned 1 exit status
make[2]: *** [../libs/armeabi-v7a/libSDL2.so] Error 1
make[1]: *** [CMakeFiles/SDL2.dir/all] Error 2
make: *** [all] Error 2

Thank you for any ideas.
Michael
Build SDL2 Demo using CMake for Android
Alvin Beach

Posted: Sat Nov 23, 2013 7:21 pm
I haven't tried using cmake, but you might need to link the math library? I see undefined reference to sqrt, atan2, ceil, etc. Perhaps setup CMakeLists.txt to emit '-lm'.
May not solve all the undefined references, but get rid of a few.
HTH,
Alvin On Nov 23, 2013 2:58 PM, 'Laz-Roc' wrote:
Quote:
Have been away for awhile, but I'm back to tackle that Android + CMake problem again.
Well, I think I've been successful building a static SDL2 library with CMake, but wasn't able to build an app so I don't know if it's working. Vice versa, I couldn't build a static library with the provided SDL2 README, but a demo with a shared library.
I'd like to build a shared library, anyway. So I slightly modified my CMakeLists.txt to building a shared library by adding the SHARED tag.
Again, it creates the makefiles, and builds the object files. But I don't know how to solve the undefined reference error. Here are some of the errors (I stripped similar errors; here is the full error message):
Quote:
Linking C shared library ../libs/armeabi-v7a/libSDL2.so
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/SDL_assert.c.o: in function SDL_ReportAssertion:SDL_assert.c(.text.SDL_ReportAssertion+0x30): error: undefined reference to 'SDL_AtomicLock'
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/SDL_assert.c.o: in function SDL_ReportAssertion:SDL_assert.c(.text.SDL_ReportAssertion+0x80): error: undefined reference to 'SDL_AtomicUnlock'
/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/audio/SDL_audio.c.o: in function bootstrap:SDL_audio.c(.data.rel.ro.bootstrap+0x0): error: undefined reference to 'DUMMYAUD_bootstrap'
/Android/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: CMakeFiles/SDL2.dir/SDL/src/stdlib/SDL_stdlib.c.o: in function SDL_atan:SDL_stdlib.c(.text.SDL_atan+0x14): error: undefined reference to 'atan'
collect2: ld returned 1 exit status
make[2]: *** [../libs/armeabi-v7a/libSDL2.so] Error 1
make[1]: *** [CMakeFiles/SDL2.dir/all] Error 2
make: *** [all] Error 2
Thank you for any ideas.
Michael
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Target Link Libraries Interface

Powered by phpBB © phpBB Group
Design by Vjacheslav Trushkin for phpBBStyles.com.
Content © SDL

This repository contains CMake scripts for finding the SDL2, SDL2_image andSDL2_ttf libraries and headers.

CMake itself comes with corresponding scripts for SDL 1.2, which hopefully intime will be updated for SDL2 and make this repo redundant. In the meantime, I'm putting them up here in case anyone else finds them useful.

I've tested them on Linux and Mac OS using the Makefile and XCode targets.On Linux, you'll need the SDL2 development packages installed from your distropackage manager. On Mac OS you can install the development frameworksfrom the SDL website or alternatively, if you use Homebrew you can runbrew install sdl2 to install the development packages.

Usage

General

In order to use these scripts, you first need to tell CMake where to find them, viathe CMAKE_MODULE_PATH variable. For example, if you put them in asubdirectory called cmake, then in your root CMakeLists.txt add the line

where project is the name of your project. You can then use the packagesthemselves by adding

or whatever is appropriate for your project.

mingw32 / msys

This section supplements Usage -> General section. You still are requiredto incorporate General configuration settings in you CMakeLists.txt.

Because cmake binaries for windows aren't aware of *nix/win paths conversion,default paths FindSDL2 will look in won't do any good. For that you should set SDL2_PATH variable.For example:

Target Link Libraries Private

Licence

Target_link_libraries Sdl Mac Pc

I am not the original author of these scripts. I found FindSDL2.cmakeafter some Googling, and hacked up the image and ttf scripts from theSDL1 versions that come with CMake. The original scripts, and my changes,are released under the two-clause BSD licence.

Target_link_libraries Sdl Mac Os

Bugs

Target_link_libraries Sdl Mac Free

Target link libraries interface

Target_link_libraries Sdl Mac 2017

These scripts are provided in the hope that you might find them useful. Theywork for me and hopefully they'll work for you too. If you fix anyissues with them then I'd appreciate a pull request so otherusers can get your fixes too, but that's up to you :-).