LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX
User Name
Password
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.

Notices


Reply
  Search this Thread
Old 09-08-2008, 11:41 AM   #1
smithzv
LQ Newbie
 
Registered: Feb 2008
Location: Boulder, CO USA
Distribution: Ubuntu and Android
Posts: 10

Rep: Reputation: 1
SDL.framework: How do I use it?


Hey,

I wanted to build this little example SDL program:

http://friedspace.com/SDLTest.c

I saved this a file called sdl.c. On my GNU/Linux box I had no trouble. This,

GNU/Linux$ gcc -I/usr/include/SDL -L/usr/lib sdl.c -lSDL

produces a viable executable. On OS X there are these framework things. I don't know much about them, but they appear to contain all of what is necessary to compile and link a program against, say, SDL. So I installed the SDL framework from http://www.libsdl.org/download-1.2.php (I just copied SDL.framework into /Library/Frameworks) and tried to build the same sample program via:

smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.c -framework SDL
sdl.c:3:16: error: SDL.h: No such file or directory
sdl.c:10: error: parse error before '*' token
sdl.c: In function 'setpixel':
sdl.c:12: error: 'Uint32' undeclared (first use in this function)
sdl.c:12: error: (Each undeclared identifier is reported only once
sdl.c:12: error: for each function it appears in.)
sdl.c:12: error: 'pixmem32' undeclared (first use in this function)
sdl.c:13: error: parse error before 'colour'
sdl.c:15: error: 'colour' undeclared (first use in this function)
sdl.c:15: error: 'screen' undeclared (first use in this function)
sdl.c:15: error: 'r' undeclared (first use in this function)
sdl.c:15: error: 'g' undeclared (first use in this function)
sdl.c:15: error: 'b' undeclared (first use in this function)
sdl.c:17: error: parse error before ')' token
sdl.c: At top level:
sdl.c:22: error: parse error before '*' token
sdl.c: In function 'DrawScreen':
sdl.c:26: error: 'screen' undeclared (first use in this function)
sdl.c:36: error: 'h' undeclared (first use in this function)
sdl.c: In function 'main':
sdl.c:48: error: 'SDL_Surface' undeclared (first use in this function)
sdl.c:48: error: 'screen' undeclared (first use in this function)
sdl.c:49: error: 'SDL_Event' undeclared (first use in this function)
sdl.c:49: error: parse error before 'event'
sdl.c:54: error: 'SDL_INIT_VIDEO' undeclared (first use in this function)
sdl.c:56: error: 'SDL_FULLSCREEN' undeclared (first use in this function)
sdl.c:56: error: 'SDL_HWSURFACE' undeclared (first use in this function)
sdl.c:65: error: 'event' undeclared (first use in this function)
sdl.c:69: error: 'SDL_QUIT' undeclared (first use in this function)
sdl.c:72: error: 'SDL_KEYDOWN' undeclared (first use in this function)

Okay, it cannot find the header files. I tried adding a -F/Library/Frameworks to the options but it made no difference. I tried explicitly compiling and the linking passing the framework option to the linker by hand:

smithzv@belial:[0]:~/src/work/sdl-examples$ gcc -c sdl.c -I/Library/Frameworks/SDL.framework/Headers
smithzv@belial:[0]:~/src/work/sdl-examples$ ld -framework SDL sdl.o
ld: /Library/Frameworks/SDL.framework/SDL load command 6 unknown cmd field

...still no go. I also thought that maybe I could get around the frameworks if I installed SDL through MacPorts, which I did. So I tried this (my MacPorts tree is in the default /opt/local):

smithzv@belial:[0]:~/src/work/sdl-examples$ gcc -c sdl.c -I/opt/local/include/SDL
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.o -L/opt/local/lib -lSDL
/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status

Hmmm... okay, let's check...

smithzv@belial:[0]:~/src/work/sdl-examples$ nm sdl.o
0000006c T _DrawScreen
U _SDL_Flip
U _SDL_Init
U _SDL_LockSurface
U _SDL_MapRGB
U _SDL_PollEvent
U _SDL_Quit
U _SDL_SetVideoMode
U _SDL_UnlockSurface
000001cb T _SDL_main
00000000 T _setpixel

...sure enough, no main symbol. For comparison, on the linux box...

GNU/Linux$ nm sdl.o
0000006f T DrawScreen
U SDL_Flip
U SDL_Init
U SDL_LockSurface
U SDL_MapRGB
U SDL_PollEvent
U SDL_Quit
U SDL_SetVideoMode
U SDL_UnlockSurface
000001cc T main
00000000 T setpixel

...we do get a main function.

Any thoughts on what I am doing wrong? I have reinstalled the SDL framework, but this had no effect.

Thanks for any hints,
Zach

BTW I have had a hard time finding much help on developing in OS X. If anyone has some links, I would love to check them out.
 
Old 09-08-2008, 03:06 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2020 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,383

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Welcome to Linux Questions

Quote:
sdl.c:3:16: error: SDL.h: No such file or directory
Well so far only 1 error !
But you need to install package "sdl-1.2.x"
It is on install disc 2 /l (l for libraries (L))
or get it from "getslack" e.g.
ftp://ftp.heanet.ie/mirrors/ftp.slac...pub/slackware/

Copying files from the source code to a directory
will not do.

Regards

P.S.: Slackware packages are to be installed with
the command # 'installpkg <package.tgz>'

Last edited by knudfl; 09-08-2008 at 03:15 PM.
 
Old 09-08-2008, 05:13 PM   #3
smithzv
LQ Newbie
 
Registered: Feb 2008
Location: Boulder, CO USA
Distribution: Ubuntu and Android
Posts: 10

Original Poster
Rep: Reputation: 1
Quote:
Well so far only 1 error !
But you need to install package "sdl-1.2.x"
It is on install disc 2 /l (l for libraries (L))
or get it from "getslack" e.g.
ftp://ftp.heanet.ie/mirrors/ftp.slac...pub/slackware/
Oh, sorry, there must be some misunderstanding (maybe on my part). On GNU/Linux (in fact, my Slackware box) this does work exactly as I expect. I am having a problem on OS X. I though that providing information ensuring that the program compiles and works fine elsewhere might help in trouble shooting this problem. I guess this caused more confusion than clarification.

On Mac OS X 10.4 (distributed by Apple Computers) I cannot use the thing Apple calls the SDL framework.

Quote:
Copying files from the source code to a directory
will not do.
In the README for installation:

Quote:
To Install:
Copy the SDL.framework to /Library/Frameworks
As is commonly the case with OS X software, installation requires copying a directory to a special location. This directory contains all relevant code like the header files and the shared libraries. This is a bit different from the standard "all headers in /usr/include, all libraries in /usr/lib" method of other *NIX operating systems

However, if you want to work from something that looks more like GNU/Linux, I have the SDL library installed in such a way. In this case, I get this kind of behavior (from the original post)...

Quote:
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc -c sdl.c -I/opt/local/include/SDL
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.o -L/opt/local/lib -lSDL
/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status
But, to be honest, I have no idea what kind of tom foolery OS X or Apple's version of gcc might be pulling in the background, nor do I have any verification that the library built and installed correctly (only that an error was not encountered during the build).

Thanks,
Zach
 
Old 09-08-2008, 05:37 PM   #4
smithzv
LQ Newbie
 
Registered: Feb 2008
Location: Boulder, CO USA
Distribution: Ubuntu and Android
Posts: 10

Original Poster
Rep: Reputation: 1
Okay,

I have a solution, though it is not ideal (i.e. I still do not know how to use the SDL framework). One issue is that I was not including the flag -lSDLmain for the linker. I guess this isn't necessary for the GNU/Linux build. In fact it seems that on the Slackware box libSDLmain doesn't to much at all, but on OS X it adds a bunch of Cocoa stuff. The lack of -lSDLmain explains the missing symbol on OS X.

After adding -lSDLmain, I get more undefined symbols. These are from Cocoa.

Code:
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.c -I/opt/local/include/SDL -L/opt/local/lib -lSDLmain -lSDL 
/usr/bin/ld: Undefined symbols:
.objc_class_name_NSApplication
.objc_class_name_NSAutoreleasePool
.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
___CFConstantStringClassReference
_objc_msgSend
collect2: ld returned 1 exit status
So I need to add a -framework Cocoa in order to resolve them. Problem solved, except I am still using the MacPorts version of SDL, not the framework in /Library/Frameworks. But I guess the Cocoa framework worked as expected. Maybe I am using them right and there is something wrong with the SDL distribution.

Well, I guess this will work well enough for now,
Zach
 
Old 09-10-2008, 08:41 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Did you try this:
http://gpwiki.org/index.php/C:How_to...MacOS_X:_Xcode
 
Old 09-11-2008, 11:42 AM   #6
smithzv
LQ Newbie
 
Registered: Feb 2008
Location: Boulder, CO USA
Distribution: Ubuntu and Android
Posts: 10

Original Poster
Rep: Reputation: 1
Looks like I need some RTFM over here.

I have little desire to touch ProjectBuilder/Xcode. For the most part, I really want to use OS X as if it were a Linux box. That way what I write on it will run at home. So this exact section isn't so much help, but later on a link caught my eye which lead me to the OS X FAQ for SDL. Embarrassingly enough, this answered almost all of my questions, which I guess must therefore be frequently asked. I know how unresearched threads like this can be annoying, so I will apologize to the readers out there.

Anyway, in case someone else is searching on this, here is the FAQ page:

http://www.libsdl.org/faq.php?action...ies&category=7

Basically, linking against SDL.framework is only for Project Builder/Xcode stuff, not for C programs like the one I was building. The FAQ does hint that some C/C++ projects (I know not which) that do link against SDL.framework, but it suggests that it takes some trickery. It looks like the solution I finally stumbled upon is the suggested solution for SDL on OS X in C/C++.

Zach
 
Old 02-09-2012, 09:06 AM   #7
afablee
LQ Newbie
 
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Hi Zach,

I've been trying to figure this out for the past 2 days as well. Your link has been moved. Can you shine any light on this?

I would like to use the framework to link to my .o files. It seems to work now with the SDL framework:

all: main.o
g++ -g -Wall main.o -lSDLmain -framework Cocoa -framework SDL
main.o: main.cpp
g++ -g -c -Wall main.cpp
clean:
rm -f *.o
rm -f a.out

But when I try to add the SDL_image framework, I receive the following:

g++ -g -Wall main.o -lSDLmain -framework Cocoa -framework SDL -framework


/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:28:17: error: SDL.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:29:25: error: SDL_version.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:30:24: error: begin_code.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:134:24: error: close_code.h: No such file or directory

I can see that the SDL.h header does exist in the SDL.framework, so I try to include it with -I/Library/Frameworks/SDL.framework/Headers/. So now I have the following:

g++ -g -Wall main.o -lSDLmain -framework Cocoa -framework SDL -framework -I/Library/Frameworks/SDL.framework/Headers/

But I still receive the same errors:


In file included from main.cpp:11:
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:28:17: error: SDL.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:29:25: error: SDL_version.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:30:24: error: begin_code.h: No such file or directory
/Library/Frameworks/SDL_image.framework/Headers/SDL_image.h:134:24: error: close_code.h: No such file or directory
make: *** [main.o] Error 1

**UPDATE**

Nevermind. I wasn't including the the headers with the -I with .cpp but doing it after my .cpp files were turned into machine code at .o
I'm still learning.

Last edited by afablee; 02-09-2012 at 09:08 AM.
 
Old 03-10-2012, 01:14 AM   #8
myhealth
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: 0
if I disabled letting it wait for a vertical retrace (I assume that's what you meant by Vsync) wouldn't it tear the screen? Also, I do plan on drawing more stuff and doing more processing between flips, the problem is that there is too much time between the flips to get a good frame rate.
 
Old 03-10-2012, 02:33 AM   #9
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,900

Rep: Reputation: 637Reputation: 637Reputation: 637Reputation: 637Reputation: 637Reputation: 637
This thread is over 3 years old. You are better off starting a new thread so you can get up to date information.

@ myhealth, did you read the LQ rules when you signed up?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The dotnet framework tvks Linux - General 3 03-02-2007 03:40 AM
SDL is installed, included and linked, but will not compile SDL code mansizerooster Programming 10 05-31-2006 04:18 AM
Sourcecompiling Problem...The sdl-config script installed by SDL could not be found. deepclutch Debian 1 12-15-2005 12:15 PM
Trying to program an SDL application but cannot find the SDL.h file:SuSE 9.2&KDevelop pujolasdf Linux - Newbie 4 03-13-2005 07:50 AM
php framework pipio Linux - Software 1 06-27-2004 10:35 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration