SDL issues with iPhone development

Hello all,

I am working with an iPhone application using the iPhone SDL libraries provided by SDL 1.3. I’m confused as to how to specify to XCode that I want to run my “main” function.

I tried:

#ifdef main
#undef main
#endif

Without doing that, I get conflicts with _SDL_main:

collect2: ld returned 1 exit status
symbol(s) not found
_SDL_main in main.o
"_event_loop", referenced from:
_SDL_main in main.o
"_init_timers", referenced from:
_SDL_main in main.o
"_init_video", referenced from:

where event_loop, init_timers and init_video are functions I have specified in different header files with the code in their respective source files.

If I do put that #ifdef in there, I get the following:

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 failed with exit code 1
duplicate symbol _main in lib/libSDLSimulator.a(SDL_uikitappdelegate.o) and /Users/charlieevans/Documents/KepSiegeGame/build/KepSiegeGame.build/Debug-iphonesimulator/KepSiegeGame.build/Objects-normal/i386/main.o

Now, for a third way, I completely commented out my main function. The error I get (which is different than the ones above) is as follows:

collect2: ld returned 1 exit status
symbol(s) not found
-[SDLUIKitDelegate applicationDidFinishLaunching:] in libSDLSimulator.a(SDL_uikitappdelegate.o)
"_SDL_main", referenced from:

I know this is a long list of different things, but I’m at my wits end here and just cannot figure it out. If someone has some insight into trying something or what I am doing wrong, your help would be great appreciated. Thank you

Hi Charlie-

Include <SDL/SDL.h> in the file that contains main, and take out the
#ifdef main stuff.On 3 May 2009, at 20:00, Evans, Charlie wrote:

Hello all,

I am working with an iPhone application using the iPhone SDL
libraries provided by SDL 1.3. I’m confused as to how to specify to
XCode that I want to run my “main” function.

I tried:

#ifdef main
#undef main
#endif

Without doing that, I get conflicts with _SDL_main:

collect2: ld returned 1 exit status
symbol(s) not found
_SDL_main in main.o
"_event_loop", referenced from:
_SDL_main in main.o
"_init_timers", referenced from:
_SDL_main in main.o
"_init_video", referenced from:

where event_loop, init_timers and init_video are functions I have
specified in different header files with the code in their
respective source files.

If I do put that #ifdef in there, I get the following:

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/
bin/gcc-4.0 failed with exit code 1
duplicate symbol _main in lib/
libSDLSimulator.a(SDL_uikitappdelegate.o) and /Users/charlieevans/
Documents/KepSiegeGame/build/KepSiegeGame.build/Debug-
iphonesimulator/KepSiegeGame.build/Objects-normal/i386/main.o

Now, for a third way, I completely commented out my main function.
The error I get (which is different than the ones above) is as
follows:

collect2: ld returned 1 exit status
symbol(s) not found
-[SDLUIKitDelegate applicationDidFinishLaunching:] in
libSDLSimulator.a(SDL_uikitappdelegate.o)
"_SDL_main", referenced from:

I know this is a long list of different things, but I’m at my wits
end here and just cannot figure it out. If someone has some insight
into trying something or what I am doing wrong, your help would be
great appreciated. Thank you


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3912 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090503/af39f27f/attachment.bin

Hello again,

I already have the SDL.h file included. I read on the SDL FAQ to put the SDLmain.h/.m files in the project, but that doesn’t work either as it complains about Cocoa. I tried including the Cocoa framework as well, but that did no good. My main function is setup exactly like it says in the FAQ, but to no avail. Here is my main.c file for reference:

#include “SDL.h”
#include <stdio.h>
#include “timers.h”
#include “render.h”
#include “eventloop.h”

int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) {
printf(“Could not initialize SDL\n”);
}

init_video(); //refers to render.h
init_timers(); //refers to timers.h
event_loop(); //refers to eventloop.h
return 0;

}

I also saw something about telling XCode to not use the project prefix file if I wanted to use a .c file instead of a .m file, but I have no idea how to locate that. Thanks again

Hello,

You’re right about not including Cocoa. Cocoa doesn’t exist on iPhone
(uses UIKit instead).

Ignore what the SDL FAQ might say about Mac OS X, the iPhone port is
separate. Follow the directions in ReadMe.iphoneos instead.

The previous poster was also correct in that the stuff you had in there
before (the #ifdef main) should not be there.

About the prefix file, you only need to tell XCode not to include it if
you rename main.m to main.c – otherwise you should be fine. If you
want XCode to not include it you can find this in the build settings of
your app (search for prefix).

  • Holmes

Evans, Charlie wrote:>

Hello again,

I already have the SDL.h file included. I read on the SDL FAQ to put
the SDLmain.h/.m files in the project, but that doesn’t work either as
it complains about Cocoa. I tried including the Cocoa framework as
well, but that did no good. My main function is setup exactly like it
says in the FAQ, but to no avail. Here is my main.c file for reference:

#include “SDL.h”
#include <stdio.h>
#include “timers.h”
#include “render.h”
#include “eventloop.h”

int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) {
printf(“Could not initialize SDL\n”);
}

init_video(); //refers to render.h
init_timers(); //refers to timers.h
event_loop(); //refers to eventloop.h
return 0;

}

I also saw something about telling XCode to not use the project prefix
file if I wanted to use a .c file instead of a .m file, but I have no
idea how to locate that. Thanks again



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yeah I have tried all of that too. I’m not sure it was using a prefix file to begin with as the only option I could find that related to this matter was already unchecked. I also followed the directions in the readme.iphoneos file, both the “easiest” and “more manual” methods. I’m currently using the easiest method.

Now by taking the approach that is being told to me, I still get the following batch of errors:

collect2: ld returned 1 exit status
symbol(s) not found
_SDL_main in main.o
"_event_loop", referenced from:
_SDL_main in main.o
"_init_timers", referenced from:
_SDL_main in main.o
"_init_video", referenced from:

Now, would this be because XCode can’t find those particular functions in the SDL_main function? And if so, how can that be remedied? Thanks again for all your help.

Hello,

My guess from inspecting the errors is that the libSDLiPhone.a or
libSDLiPhoneSimulator.a aren’t being linked to the project properly.

It looks like the problems you’ve encountered have happened because the
project template no longer includes copies of the header files or the .a
library files.

So here is what I did to get a successful build from the template:

  1. compiled libSDLiPhone.a (had to remove references to
    SDLRevision.h to get it to compile)
  2. compiled libSDLSimulator.a
  3. compiled and installed project template
  4. created new project from template
  5. removed libSDLiPhone.a and libSDLSimulator.a from project tree in new
    project … links were dead, project expected the files somewhere else
    … copied these files back into the project from
    XCodeiPhoneOS/SDL/build/… instead
  6. copied header files to project from SDL’s “include” directory
  7. removed references to SDL_RenderFill in main.c … these have become
    outdated because the SDL_RenderFill function has changed since the
    template was last updated.

Sorry for the long process, let me know if you hit a roadblock somewhere
in these steps.

  • Holmes

Evans, Charlie wrote:>

Yeah I have tried all of that too. I’m not sure it was using a prefix
file to begin with as the only option I could find that related to
this matter was already unchecked. I also followed the directions in
the readme.iphoneos file, both the “easiest” and "more manual"
methods. I’m currently using the easiest method.

Now by taking the approach that is being told to me, I still get the
following batch of errors:

collect2: ld returned 1 exit status
symbol(s) not found
_SDL_main in main.o
"_event_loop", referenced from:
_SDL_main in main.o
"_init_timers", referenced from:
_SDL_main in main.o
"_init_video", referenced from:

Now, would this be because XCode can’t find those particular functions
in the SDL_main function? And if so, how can that be remedied? Thanks
again for all your help.



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello yet again,

I have tried your suggestion. Is the program supposed to show up with a black screen on the simulator? That’s all mine has ever done when running that template. If not, then that could be a potential problem as well. But I also tried applying those changes to my project, but I still receive the same errors. Any thoughts?

Hello again,

I was able to run the template this afternoon and produce its intended
effect (randomly sized and colored rectangles) by changing the calls to
SDL_RenderFill. I’ve included my modified main.c for you after my response.

If you’re still getting the same errors (missing symbols) with your
project after following my suggestions I’m not sure what to do. I would
just be making absolutely certain that libSDLSimulator.a and
libSDLiPhoneOS.a are included in the project tree (and not highlighted
red) and that under Targets->your-app-name->Link Binary With Libraries
(in the project tree) libSDLiPhoneOS.a and libSDLSimulator.a are
included in the list.

  • Holmes

/************* /
/*

  • rectangles.c
  • written by Holmes Futrell
  • use however you want
    */

#include “SDL.h”
#include <time.h>

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480

int
randomInt(int min, int max)
{
return min + rand() % (max - min + 1);
}

void
render(void)
{

Uint8 r, g, b;
/*  Come up with a random rectangle */
SDL_Rect rect;
rect.w = randomInt(64, 128);
rect.h = randomInt(64, 128);
rect.x = randomInt(0, SCREEN_WIDTH);
rect.y = randomInt(0, SCREEN_HEIGHT);

/* Come up with a random color */
r = randomInt(50, 255);
g = randomInt(50, 255);
b = randomInt(50, 255);

/*  Fill the rectangle in the color */
SDL_SetRenderDrawColor(r, g, b, 255);
SDL_RenderFill(&rect);

/* update screen */
SDL_RenderPresent();

}

int
main(int argc, char *argv[])
{

SDL_WindowID windowID;
int done;
SDL_Event event;

/* initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    printf("Could not initialize SDL\n");
}

/* seed random number generator */
srand(time(NULL));

/* create window and renderer */
windowID =
    SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                     SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (windowID == 0) {
    printf("Could not initialize Window\n");
}
if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
    printf("Could not create renderer\n");
}

/* Fill screen with black */
SDL_SetRenderDrawColor(0, 0, 0, 255);
SDL_RenderFill(NULL);
//  SDL_RenderFill(0, 0, 0, 0, NULL);

/* Enter render loop, waiting for user to quit */
done = 0;
while (!done) {
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_QUIT) {
            done = 1;
        }
    }
    render();
    SDL_Delay(1);
}

/* shutdown SDL */
SDL_Quit();

return 0;

}

Evans, Charlie wrote:>

Hello yet again,

I have tried your suggestion. Is the program supposed to show up with
a black screen on the simulator? That’s all mine has ever done when
running that template. If not, then that could be a potential problem
as well. But I also tried applying those changes to my project, but I
still receive the same errors. Any thoughts?



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org