Unable to connect to SDL in Xcode4!

I am completely upset! I tried to get acclimatized using the SDL tonight, but I hit a brick wall trying to link it using Xcode4! Here is what I did. I downloaded the SDL runtime and development libraries v1.2.14. I followed all directions (by dragging SDL.framework to / Library / Frameworks) to the point where I realized that the templates did not work in XC4 the way they were used in XC3.x. I ran the templates and tried to add the framework to the vanilla cocoa application. (Created from the built-in application template.) I added the SDLMain.hm and .nib files and tried to create. Immediately I received the error message "SDL.h". I manually adjusted the setting of the header search path for all configurations, although I thought it was not necessary if I directly referred to the structure. I went around the missing header file this way, but started to hit linker errors.

"_SDL_main", referenced from: -[SDLMain applicationDidFinishLaunching:] in SDLMain.o 

I tried all different executions to satisfy both my linker and compiler. I moved the frames to my user folder in ~ / Library / Frameworks, I played with the import syntax <> and "". I started a completely new project and repeated everything. I'm lost! can anyone help?

+4
source share
2 answers

I know this is old, but if someone trips about it now.

Xcode by default creates the main function with declaration

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

While the SDL is looking for a function with declaration

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

Note the lack of a constant in char * argv []. It appears that when the SDL looks for char * [], Xcode gives it const char * [] and that it cannot find the character.

I really want the SDL to stop renaming my functions! There must be a better solution, but hey, it will do for now.

+5
source

I do not know if you are still looking for this, but I think because the SDL is looking for the name of the C symbol, but your main one is declared in a C ++ file.

You need to do:

 extern "C" int main(int argc, char *argv[]) { ... } 

It is "documented" in SDL_main.h:

 /** The application main() function must be called with C linkage, * and should be declared like this: * @code * #ifdef __cplusplus * extern "C" * #endif * int main(int argc, char *argv[]) * { * } * @endcode */ 
+2
source

All Articles