无法链接到 XCode4 中的 SDL!

发布于 2024-11-10 14:25:31 字数 597 浏览 1 评论 0原文

我彻底沮丧了!今晚我试图适应 SDL,但在尝试通过 XCode4 链接到它时遇到了困难!这就是我所做的。我下载了 v1.2.14 的 SDL 框架运行时库和开发 xtra。我遵循了所有指示(将 SDL.framework 拖放到 /Library/Frameworks 中),直到我意识到模板在 XC4 中无法像在 XC3.x 中那样工作。我在模板上下了注,并尝试将框架添加到普通的可可应用程序中。 (从内置应用程序模板创建。)我添加了 SDLMain .h .m 和 .nib 文件并尝试构建。我立即收到一条错误消息,说找不到“SDL.h”。我手动调整了所有配置的标头搜索路径设置,但我认为如果我直接引用框架,则不需要这样做。我通过这种方式解决了丢失的头文件,但开始遇到链接器错误。

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

我已经尝试了满足我的链接器和编译器的所有不同的表现形式。我已将框架移动到 ~/Library/Frameworks 下的用户文件夹中,我已经玩过两个 <>和“”导入语法。我开始了一个全新的项目并重复了一切。我迷路了!有人可以帮忙吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-11-17 14:25:31

我知道这已经很旧了,但如果现在有人偶然发现这一点。

XCode 默认情况下创建带有声明的 main 函数,

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

而 SDL 正在寻找带有声明的函数

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

注意 char * argv[] 中缺少 const。似乎当 SDL 寻找 char * [] 时,Xcode 给它一个 const char * [] 并导致它无法找到该符号。

我真的希望 SDL 停止重命名我的函数!一定有更好的解决方案,但是,嘿,现在就这样了。

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.

如痴如狂 2024-11-17 14:25:31

我不知道你是否还在寻找这个,但我认为这是因为 SDL 正在寻找 C 符号名称,但你的 main 是在 C++ 文件中声明的。

你必须这样做:

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

它在 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
 */

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
 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文