Reputation: 11268
I am thoroughly frustrated! I was trying to get acclimated with SDL tonight but I hit a brick wall trying to link to it via XCode4! Here's what I did. I downloaded v1.2.14 of the SDL framework runtime libraries and development xtras. I followed all the directions (dragging/dropping the SDL.framework in /Library/Frameworks) up to the point where I realized that templates don't work in XC4 the way they used to in XC3.x. I punted on the templates and tried to add the framework to a vanilla cocoa application. (Created from the built-in application template.) I added the SDLMain .h .m and .nib files and tried to build. Immediately I got an error saying it couldn't find "SDL.h". I manually adjusted my header search path setting for all configs though I thought this shouldn't be necessary if I referenced the framework directly. I got around the missing header file this way but started hitting linker errors.
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
I've tried all different renditions of satisfying both my linker and compiler. I've moved the framework to my user folder under ~/Library/Frameworks, I've toyed with both <> and "" import syntax. I've started a completely brand new project and repeated everything. I'm lost! can somebody help?
Upvotes: 4
Views: 1220
Reputation: 515
I know this is old but if anyone stumbles across this now.
XCode by default creates the main function with the declaration
int main(int argc, const char * argv[])
While SDL is looking for a function with the declaration
int main(int argc, char * argv[])
Note lack of const in char * argv[]. It seem that when SDL is looking for a char * [] Xcode gives it a const char * [] and that it causing it to fail to find the symbol.
I really wish SDL would stop renaming my functions! There must be a better solution, but hey, this will do for now.
Upvotes: 5
Reputation: 21
I don't know if your still looking for that, but I think it's because SDL is looking for a C symbol name, but your main is declared in a C++ file.
You have to do:
extern "C" int main(int argc, char *argv[])
{
...
}
It's "documented" in SDL_main.h :
/** The application's 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
*/
Upvotes: 2