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.
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.
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).
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.
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.
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?
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.