SDL错误架构x86_64的未定义符号“_SDL_main” [英] SDL Error Undefined symbols for architecture x86_64 "_SDL_main"
问题描述
我使用C + + SDL Cocoa和Foundation框架在我的Mac OS X。我收到以下错误
I am using C++ with the SDL Cocoa and Foundation framework on my mac os x. I get the following error
Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found for architecture x86_64
当我运行下面的代码
#import <Foundation/Foundation.h>
#import <SDL/SDL.h>
#include "SDLMain.h"
int main(int argc, const char * argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640,480,32,SDL_DOUBLEBUF);
SDL_Event event;
bool isRunning = true;
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT){
isRunning=false;
}
}
SDL_Quit();
return 0;
}
我不知道有什么问题, SDLMain.m文件并注释掉这行代码
I have no idea what is wrong, although it seems that when I go into the SDLMain.m file and comment out this line of code
status = SDL_main (gArgc, gArgv);
程序编译没有问题。但是,它不工作。没有窗口打开像它的应该。有任何想法吗?
the program compiles with no problems. However, it doesn't work. No window opens like its supposed to. Any ideas?
推荐答案
我猜你的 main
函数签名不正确。您使用:
I bet your main
function signature is incorrect. You use:
int main(int argc, const char * argv[])
^^^^^
但SDL_main.h想要
but SDL_main.h wants
int main(int argc, char *argv[])
为什么?
你看,SDL在编译时做的事情真的很可怕:它重命名你的 main
函数到 SDL_main
,注入自己的main函数,然后调用你的函数。
You see, SDL does something really horrific when compiling: It renames your main
function to SDL_main
, injecting its own main function which, in turn, calls yours.
注意,工作,那么你可能正在编译错误的标志。可以输入以下内容获取标志:
Note that if this doesn't work, then you may be compiling with wrong flags. To be sure, get the flags by typing:
$ sdl-config --cflags --libs
有关详细信息,请参阅只包括SDL头导致链接器错误
For more information, see Simply including SDL header causes linker error
这篇关于SDL错误架构x86_64的未定义符号“_SDL_main”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!