简体   繁体   中英

SDL can't find my main function

I set up my application with the SDL Framework and it works without any error. But when I try to start my program it terminates immediately, even before entering my simple main method. Here the code:

#include "CApp.h"
#include <iostream>

int main(int argc, char* argv[]) {
    std::cout << "Hello";  
    return 0;
}

I know that SDL implements its own main function in SDLMain.m and starts manually my main function. I think that I found the code in STLMain.m that executes my main function (line 222ff):

/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];

/* Start the main event loop */
[NSApp run];

When I set a breakpoint on [NSApp run] and make a step forward the program terminates.

SDL #define s main to SDL_main in order to transparently use its own main implementation. Since you haven't included any SDL headers, you don't have that macro in scope. It should work to simply rename your main to SDL_main or include an SDL header such as SDL.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM