xCode iOS build failing with linker error

I am following the Lazy Foo tutorial “Setting up SDL 2 on Mac iOS” and have reached Step 8: “The project should now build and run with the default source”. But it doesn’t - I get a fatal linker error “ld: library not found for -lSDL2”.

I’ve added libSDL2.a to the ‘Link Binary With Libraries’ build phase, as instructed, and I’ve checked that it is the correct architecture (x86_64, for the iPhone simulator) so I don’t know what’s wrong. I’m running Xcode 9.2 on Mac OS 10.13.2 if it matters.

Any ideas? I’ve very little experience with Mac OS or Xcode so I’m dependent on following a detailed tutorial.

Richard.

If it helps, I follow different instructions. There is a command line tool for xcode, it’s named xcodebuild. I use it with this script to generate all SDL libraries for IOS Simulator/Device & Release/Debug in one shot (https://bugzilla.libsdl.org/show_bug.cgi?id=2302).

Then, for each application, I have a custom CMakeLists (see CMakeLists.txt (2.3 KB)) and I generate an Xcode project that will allow to compile my app.

Thanks, I’ll try it.

I’m afraid I’m struggling with this, no doubt because of my inexperience with Mac OS. Following your instructions at Bugzilla this is what I have tried. I first created the following directories:

~/release/Release_SDL_IOS/SDL
~/release/Release_SDL_IOS/SDL_image
~/release/Release_SDL_IOS/SDL_ttf
~/release/Release_SDL_IOS/SDL_mixer

Then I ran your script:

./ios_build_libs.sh

But it immediately reports:

./ios_build_libs.sh: line 15: cd: /Users/Richard/release/Release_SDL_IOS//SDL/Xcode-iOS/SDL/: No such file or directory

What did I do wrong?

SDL, SDL_image, SDL_ttf, SDL_mixer need to be filled with real SDL sources (by doing something like “hg clone http://hg.libsdl.org/SDL SDL)”.

I’ve never used Mercurial and don’t have the ‘hg’ command. I’ve found another script online which does the download automatically (using wget); I’ll try that because it will probably be easier for me (I realise that I will need to change the SDL version number).

I guess, you can get mercurial tool from https://www.mercurial-scm.org/wiki/Download#Mac_OS_X
The advantage is that you’ll have the latest SDL sources.
This script is a modification of the one I wrote!

OK, I’ve now successfully built libSDL2.a from the script - but it’s made no difference. When attempting to build the default Xcode project I get the same error. In case it helps with diagnosis, if I delete libSDL2.a from the ‘Link Binary With Libraries’ list I get this error:

ld: entry point (_main) undefined. for architecture x86_64

But if I include libSDL2.a in the list I get this error:

ld: library not found for -lSDL2

So, somewhat counter-intuitively, I get the “library not found” error only when the library is included! I’m sure this is just my inexperience with Xcode and Mac OS, but it’s frustrating that I can make no progress.

Use the example of CMakeLists from my first message to generate an xcode project, with lastest CMake.

I’m not, at this stage, wanting to generate my own project but instead trying to work through the tutorials to gain an understanding of Xcode and iOS. I’ve had a quick look at your CMakeLists file but to the extent that I understand it (which is not a lot!) it seems to be building for deployment on an actual iOS device. With my current level of knowledge I will want to be building for the simulator, and I don’t even know how to run the simulator outside of Xcode!

It would be great if somebody could document a non-GUI (script file) way of building and testing a sample iOS SDL app ‘from scratch’, in as much detail as the Lazy Foo tutorials provide, so that a complete beginner like me can follow it. But without that I would be jumping in at the deep end - and sinking!

you can do this with this cmakelist file.
modify it to reference a helloword sdl file.
generate the xcode project with cmake, and open it with xcode.
click to build you hello world for device and/or simulator.

I’m afraid I have no idea how to do this. You are assuming a level of knowledge that I do not possess. :cry:

Getting back to the original issue, it looks as though the “library not found for -lSDL2” error is probably arising because it is expecting to find a dynamic library (libSDL2.dylib) as well as, or instead of, libSDL2.a. Does anybody have any idea what I need to change to stop it wanting a dynamic library, or will I need to build one?

Going back a step, I’ve tried to use your script to build SDL2_ttf, but it is failing to find the SDL headers (SDL.h etc.). Can I specify a search path somehow? Or must I copy the headers from SDL into SDL_ttf?

Nothing to modify. Relative path to SDL includes is correctly set inside xcode SDL_ttf project.

Looking in the SDL_ttf Xcode project the search path is set to ../../SDL/include but mine is ../../SDL2-2.0.7/include which explains the failure. It seems to be quite conventional to unpack the SDL zip files into directories with the same name as the file (so I have SDL2-2.0.7/ and SDL2_ttf-2.0.14/) and this is what the wget command does in the script I am using. I suppose I could use links to resolve the problem without having to rename the directories.