How can one set up SDL in Netbeans on a Mac (Lion)?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

I have been trying for a while and cannot get anywhere with trying to use SDL in Netbeans on my Mac running Lion. Does anyone know how to do this?
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by Ginto8 »

I'm sure there are a few people who could tell you multiple ways to do this, but to be helpful you probably want to tell people 1. what you've already done and 2. what didn't happen that you thought would.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by avansc »

C/++ or java?

If C/++ then you should maybe look into xcode. Its much nicer, and I believe there are templates.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by Light-Dark »

avansc wrote:C/++ or java?

If C/++ then you should maybe look into xcode. Its much nicer, and I believe there are templates.
good god, they ported SDL to java?, thats a bigger waste of time than trying to beat ninja gaiden on NES.
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by avansc »

Light-Dark wrote:
avansc wrote:C/++ or java?

If C/++ then you should maybe look into xcode. Its much nicer, and I believe there are templates.
good god, they ported SDL to java?, thats a bigger waste of time than trying to beat ninja gaiden on NES.
Oh yeah? So what constructive things do you do with your time?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

I had tried using XCode earlier, but it gave me an error saying that "_main" was causing issues. I followed multiple guides and tutorials, but no luck. And I am doing this all in C++.
User avatar
szdarkhack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 61
Joined: Fri May 08, 2009 2:31 am

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by szdarkhack »

wabushooo wrote:I had tried using XCode earlier, but it gave me an error saying that "_main" was causing issues. I followed multiple guides and tutorials, but no luck. And I am doing this all in C++.
http://www.cplusplus.com/forum/general/11692/

This could be related to your issue, it's a common issue with SDL 1.2 and a pretty stupid design decision. Thankfully, it's no longer used with SDL 1.3, so make sure you're not including it by accident, or if you're using the older version try some of the suggestions in the linked topic.
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by Light-Dark »

avansc wrote:
Light-Dark wrote:
avansc wrote:C/++ or java?

If C/++ then you should maybe look into xcode. Its much nicer, and I believe there are templates.
good god, they ported SDL to java?, thats a bigger waste of time than trying to beat ninja gaiden on NES.
Oh yeah? So what constructive things do you do with your time?
Work on my game, turn java 'programmers' to C/++ Programmers and play Sonic Adventure ;) and sometimes if the mood is right ill play some mega man 2.
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

Ok, using the C linkage worked. I'm not sure why, but it compiled and I can see and image now. Thanks guys.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by avansc »

Light-Dark wrote: Work on my game, turn java 'programmers' to C/++ Programmers and play Sonic Adventure ;) and sometimes if the mood is right ill play some mega man 2.
Sooo... nothing...
wabushooo wrote:Ok, using the C linkage worked. I'm not sure why, but it compiled and I can see and image now. Thanks guys.
C++ name mangling causes a lot of issues if you are not careful.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

Ok, and just like that, it doesn't work at all. I used what the website had and it compiled and ran the first time, but now I end up with the same error as before. When I use what it tells me, an error is given saying that there is a confliction with SDL_main.h. Any ideas as to what is going on?
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by LeonBlade »

wabushooo wrote:Ok, and just like that, it doesn't work at all. I used what the website had and it compiled and ran the first time, but now I end up with the same error as before. When I use what it tells me, an error is given saying that there is a confliction with SDL_main.h. Any ideas as to what is going on?
With SDL on OS X you need to link the Cocoa framework and include the SDLmain.h and SDLmain.m files in order for that problem to go away.
I assume that's what you're talking about?

For example, if I try to compile this code on OS X:

Code: Select all

g++ -c SDLTest.c
g++ -o SDLTest SDLTest.o -lSDL
I will get this:

Code: Select all

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
There are two ways you can fix this, either if you have the SDLmain library where your linker can see it, you can use this:

Code: Select all

g++ -o SDLTest SDLTest.o -lSDL -lSDLmain -framework Cocoa
Or, you can also grab SDLmain.m and SDLmain.h from the Internet somewhere and compile it manually with your code like so:

Code: Select all

g++ -c SDLTest.c SDLmain.m
g++ -o SDLTest SDLTest.o SDLmain.o -lSDL -framework Cocoa
They both do the same thing, but if you have problems linking SDLmain then the second option might be your solution.
Please note that if you try and use fullscreen you might get this:

Code: Select all

<Warning>: CGDisplayBaseAddress is obsolete and returning NULL for display 0x19091a40
Your process also might not kill properly so you'd have to kill -9 pid it (I had to because Control+C wasn't killing it launching it from the terminal). So if you get this problem, it's because Lion changed some things around and it broke. There honestly might be a fix so by all means go look it up, I just didn't bother to. ;)

Here's that test code just to show it's working just fine.
Image

Hope this helps, everything I did here I literally built as I was writing it, so you shouldn't have any problems. Obviously, I'm compiling this with G++ in the terminal, but it shouldn't be that difficult to link SDLmain and the Cocoa framework in whatever IDE you want to use.
There's no place like ~/
wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

Everytime I try this, I get an error saying that -lSDL does not exist. This may have been the root of my problem, but what can I do to get that in the correct place?

I'll also make note that I had used SDL fine in Snow Leopard, but now Lion seems to have moved many things around.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by LeonBlade »

wabushooo wrote:Everytime I try this, I get an error saying that -lSDL does not exist. This may have been the root of my problem, but what can I do to get that in the correct place?

I'll also make note that I had used SDL fine in Snow Leopard, but now Lion seems to have moved many things around.
You might have to reinstall the SDL framework onto your computer where your compiler can link to it.
One way you might be able to get it to work is by using a package manager for OS X like brew and then link from your /usr/local/Cellar or wherever you install it.
You simply run:

Code: Select all

brew install sdl
And then you just let it do its thing, please note though the version that it will be downloading which in my case is 1.2.14.
It should symlink SDL into /usr/local by default, and there you can link your compiler to find the SDL library.
You might have to run sudo brew link sdl after you install if you get this error:

Code: Select all

Error: The linking step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link sdl'
So just keep note of that when doing it. Obviously if you don't want to go through the trouble of setting up a package manager, you can alternatively link to the SDL framework itself like you do with cocoa like this:

Code: Select all

-framework SDL
Of course assuming you have the SDL.framework file somewhere where your compiler can see it.

Either way should work the same, potential version differences aside.
Hopefully this will help as well, and again I ran the brew command while typing this and checked my symlinks to make sure everything was being linked over properly.
Happy Thanksgiving by the way (if you're from America). :lol:
There's no place like ~/
wabushooo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Sun Nov 20, 2011 1:30 pm

Re: How can one set up SDL in Netbeans on a Mac (Lion)?

Post by wabushooo »

Using brew got it to work, and the application runs, but I now get the warning in terminal that you had before. Any idea what this means? Also, it tried to go fullscreen for me, and I didn't see anything in the window. It's probably an issue in the code. Thanks though for showing me how get SDL installed, and happy Thanksgiving to you too (assuming you're in America) :D
Post Reply