xcode 架构 x86_64“_SDL_main”的 SDL 错误未定义符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14543150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SDL Error Undefined symbols for architecture x86_64 "_SDL_main"
提问by William Oliver
I am using C++ with the SDL Cocoa and Foundation framework on my mac os x. I get the following error
我在我的 mac os x 上使用 C++ 和 SDL Cocoa 和 Foundation 框架。我收到以下错误
Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found for architecture x86_64
when I run the following code
当我运行以下代码时
#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;
}
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
我不知道出了什么问题,尽管当我进入 SDLMain.m 文件并注释掉这行代码时
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?
程序编译没有问题。但是,它不起作用。没有窗口像它应该的那样打开。有任何想法吗?
回答by csl
I bet your main
function signature is incorrect. You use:
我敢打赌你的main
函数签名不正确。你用:
int main(int argc, const char * argv[])
^^^^^
but SDL_main.h wants
但 SDL_main.h 想要
int main(int argc, char *argv[])
Why?
为什么?
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.
你看,SDL 在编译时做了一些非常可怕的事情:它将你的main
函数重命名为SDL_main
,注入它自己的 main 函数,它反过来调用你的函数。
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
For more information, see Simply including SDL header causes linker error
有关详细信息,请参阅仅包含 SDL 标头会导致链接器错误
回答by macco
I had the same problem, even though my main signature was correct. I Found the answer here: SDL in XCode 4.3.2 SDLMain.o undefined symbols
我遇到了同样的问题,即使我的主要签名是正确的。我在这里找到了答案:SDL in XCode 4.3.2 SDLMain.o undefined symbols
Turned out the problem was that I added SDLMain.m and SDLMain.h (according to a suggestion on the libSDL website about OS X frameworks) to an existing SDL project which messed up with main. Bottom line is that you don't need those files just because you are using Cocoa -- SDL's own test apps don't use it either and run just fine on OS X.
原来问题是我将 SDLMain.m 和 SDLMain.h(根据 libSDL 网站上关于 OS X 框架的建议)添加到与 main 混淆的现有 SDL 项目中。最重要的是,您不需要这些文件只是因为您使用的是 Cocoa——SDL 自己的测试应用程序也不使用它,并且在 OS X 上运行得很好。