Page 1 of 2

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

Posted: Sun Nov 20, 2011 1:34 pm
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?

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

Posted: Sun Nov 20, 2011 2:01 pm
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.

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

Posted: Sun Nov 20, 2011 2:06 pm
by avansc
C/++ or java?

If C/++ then you should maybe look into xcode. Its much nicer, and I believe there are templates.

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

Posted: Sun Nov 20, 2011 3:11 pm
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.

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

Posted: Sun Nov 20, 2011 4:15 pm
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?

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

Posted: Sun Nov 20, 2011 5:22 pm
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++.

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

Posted: Sun Nov 20, 2011 7:34 pm
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.

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

Posted: Mon Nov 21, 2011 1:27 am
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.

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

Posted: Mon Nov 21, 2011 4:57 pm
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.

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

Posted: Mon Nov 21, 2011 5:29 pm
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.

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

Posted: Wed Nov 23, 2011 5:54 pm
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?

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

Posted: Thu Nov 24, 2011 5:32 am
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.

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

Posted: Thu Nov 24, 2011 9:30 am
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.

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

Posted: Thu Nov 24, 2011 12:12 pm
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:

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

Posted: Thu Nov 24, 2011 2:26 pm
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