How do I compile an SDL app on PrjctBlder in OSX 10.2.9?

Apprentice
Posts: 13
Joined: 2006.10
Post: #1
I have an SDL based game that is in Alpha stages that I am making for my teacher. After struggling to find a way to compile SDL on OSX 10.2.9(I'll talk about why I have that version later), using the 2002 dev tools found at connect.apple.com. I almost gave up until someone told me about Project Builder, that came with the dev tools. Apparently, that was the original Xcode, but was not called so. There is no SDL template in project builder, and it seem the person didn't have any idea how I would go about compiling it under Project Builder. So... how would I do so to compile this game under Project Builder for Mac OSX 10.2.9?

Now why I have Mac OSX 10.2.9: That is just what I have. And I do not have money to spend on an upgraded version. And really I have not been using Mac OSX at all much, until I just recently (like within the passed 13 hours of this posting), upgraded from OSX 10.1.x to 10.2.9. So, in my Mac Life, I am only about 13 hours old, not including the very short past forgotten experiences using Mac OSX.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You have 10.2.8, there is no 10.2.9 Rasp

Older versions of SDL came with Project Builder templates, but who knows whether you can get those any more, and whether the old templates would work with new versions of SDL...

Personally, I'd just make a "Carbon Application" project, delete the stuff that comes with it, add SDL.framework, SDLMain.h and SDLMain.m, and go from there.

If you have a Linux build system that works, you could probably use that with small modifications, too.
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #3
Shows you how much I know about Mac OSX.

I have a Makefile for my Linux build... but I don't know how I would even attempt to add a Framework to the command line. I tried -framework SDL but that doesn't work. And that is where my Mac knowledge ends. Instead of using Project Builder, what could I do to compile using a Makefile? BTW... I could install SDL through source... so no UNIX style install of SDL.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
-framework SDL will work if SDL.framework is in /Library/Frameworks. If it's somewhere else, you'll need to add eg. -F ~/Library/Frameworks
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #5
I'm not sure how close I am to getting a compiled SDL app, but let me show you the small test app, along with the command and the output:

Code:
#include <SDL/SDL.h>
#include <iostream>
using namespace std;

int main(int argc, char*argv[]) // exactly like shown in the manual
{
    SDL_Init(SDL_INIT_VIDEO); // no need for testing the return value
    SDL_Quit();
    return 0;
}

Here is the command followed by output:

Code:
g++ sdl_file.cc -framework SDL -o sdl_file

output:

Code:
georget% g++ sdl_file.cc -framework SDL -o sdl_file
ld: /usr/lib/crt1.o illegal reference to symbol: __objcInit defined in indirectly referenced dynamic library /usr/lib/libobjc.A.dylib
georget%

I had to sudo cp SDL.framework into /Library/Frameworks/, and I also have a local copy in my home directory.

One last thing... the SDL online faq says I need to have SDLMain.m/h somehwhere in the program. What is that? What do I do with it? Never dealt with anything having an .m before.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
Try this set of commands (with SDLMain.m and SDLMain.h in the same directory)
gcc -c SDLMain.m -o SDLMain.o
g++ -c sdl_file.cc -o sdl_file.o
gcc SDLMain.o sdl_file.o -framework SDL -o sdl_file

[edited by OSC -- added a couple of -c's]
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #7
With SDLMain.h and .m in the same directory:

Code:
gcc -c SDLMain.m -o SDLMain.o

output:

Code:
georget% gcc -c SDLMain.m -o SDLMain.o
SDLMain.m:8: header file 'SDL.h' not found
SDLMain.m:75: undefined type, found `SDL_Event'
cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
georget%

Now I copied over SDL.h from the /Library/Framworks/SDL.frameworks/:


Code:
gcc -c SDLMain.m -o SDLMain.o

output:

Code:
georget% gcc -c SDLMain.m -o SDLMain.o
SDL.h:28: header file 'SDL_main.h' not found
SDL.h:29: header file 'SDL_stdinc.h' not found
SDL.h:30: header file 'SDL_audio.h' not found
SDL.h:31: header file 'SDL_cdrom.h' not found
SDL.h:32: header file 'SDL_cpuinfo.h' not found
SDL.h:33: header file 'SDL_endian.h' not found
SDL.h:34: header file 'SDL_error.h' not found
SDL.h:35: header file 'SDL_events.h' not found
SDL.h:36: header file 'SDL_loadso.h' not found
SDL.h:37: header file 'SDL_mutex.h' not found
SDL.h:38: header file 'SDL_rwops.h' not found
SDL.h:39: header file 'SDL_thread.h' not found
SDL.h:40: header file 'SDL_timer.h' not found
SDL.h:41: header file 'SDL_video.h' not found
SDL.h:42: header file 'SDL_version.h' not found
SDL.h:44: header file 'begin_code.h' not found
SDL.h:69: illegal external declaration, missing `;' after `DECLSPEC'
SDL.h:69: illegal external declaration, missing `;' after `SDLCALL'
SDL.h:69: undefined type, found `Uint32'
SDL.h:69: illegal external declaration, missing `;' after `flags'
SDL.h:72: illegal external declaration, missing `;' after `DECLSPEC'
SDL.h:72: illegal external declaration, missing `;' after `SDLCALL'
SDL.h:72: undefined type, found `Uint32'
SDL.h:72: illegal external declaration, missing `;' after `flags'
SDL.h:75: illegal external declaration, missing `;' after `DECLSPEC'
SDL.h:75: illegal external declaration, missing `;' after `SDLCALL'
SDL.h:75: undefined type, found `Uint32'
SDL.h:75: illegal external declaration, missing `;' after `flags'
SDL.h:81: undefined type, found `DECLSPEC'
SDL.h:81: illegal external declaration, missing `;' after `Uint32'
SDL.h:81: undefined type, found `Uint32'
SDL.h:86: illegal external declaration, missing `;' after `DECLSPEC'
SDL.h:86: illegal external declaration, missing `;' after `SDLCALL'
SDL.h:86: illegal external declaration, missing `;' after `void'
SDL.h:92: header file 'close_code.h' not found
SDLMain.m:75: undefined type, found `SDL_Event'
cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
georget%

I'm going to try to just make a directory with subdirectories to SDL.frameworks, see what happens. Thanks so far for the replies, I appreciate it!

--UPDATE--
Could not get what I was said I was going to do to work.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #8
Alright, add the -framework SDL flag to all the commands. I forgot about the headers, which would be included to the search path with the -framework flag.
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #9
Code:
georget% gcc -c SDLMain.m -framework SDL -o SDLMain.oSDLMain.m:8: header file 'SDL.h' not found
SDLMain.m:75: undefined type, found `SDL_Event'
cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

I did a locate SDL.framework, and it is in /Library/Frameworks/
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
-framework SDL is only for linking, it won't help here.

What you need is to change your source to include headers appropriately -- <SDL/SDL.h> -- or to add -I/Library/Frameworks/SDL.framework/Headers to your command.
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #11
Cool, OneSadCookie, it worked for making modules (.o) of the files... now here is the problem now:

(both gcc and g++ output the same error, but I need g++ for this is a c++ application)
Code:
georget% g++ SDLMain.o sdl_file.o -I/Library/Frameworks/SDL.framework/Headers -o sdl_file
ld: Undefined symbols:
.objc_class_name_NSApplication
.objc_class_name_NSAutoreleasePool
.objc_class_name_NSConstantString
.objc_class_name_NSMenu
.objc_class_name_NSMenuItem
.objc_class_name_NSObject
.objc_class_name_NSProcessInfo
.objc_class_name_NSString
_CFBundleCopyBundleURL
_CFBundleGetInfoDictionary
_CFBundleGetMainBundle
_CFRelease
_CFURLCreateCopyDeletingLastPathComponent
_CFURLGetFileSystemRepresentation
_CPSEnableForegroundOperation
_CPSGetCurrentProcess
_CPSSetFrontProcess
_NSAllocateMemoryPages
_NSApp
_NSDeallocateMemoryPages
_SDL_PushEvent
__NSConstantStringClassReference
_objc_msgSend
_SDL_Init
_SDL_Quit
georget%

Here is the actual code:

Code:
#include <SDL/SDL.h>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
        SDL_Init(SDL_INIT_VIDEO);
        SDL_Quit();
        return 0;
}
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
Add -framework Cocoa to your link command.
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #13
Here is the output from your suggestion:

Code:
georget% g++ SDLMain.o sdl_file.o -framework Cocoa -I/Library/Frameworks/SDL.framework/Headers -o sdl_file
ld: Undefined symbols:
_SDL_PushEvent
_SDL_Init
_SDL_Quit
georget%
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #14
you're missing -framework SDL now Wink
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #15
Ok, I got a small SDL app to work just fine. Thanks!
Quote this message in a reply
Post Reply