在 Mac 上编译 SDL 游戏

发布于 2024-08-15 12:47:59 字数 128 浏览 3 评论 0原文

我有一台 Mac,我正在尝试编译我的项目。 wiki 上的标准: g++ sdl.cpp -lSDLmain -lSDL -framework Cocoa 似乎不起作用,它返回找不到 -lSDL 和 -lSDLmain 。任何帮助将不胜感激。

I have a mac and I am trying to compile my projects. The standard on the wiki: g++ sdl.cpp -lSDLmain -lSDL -framework Cocoa does not seem to be working it returns that it cannot find -lSDL and -lSDLmain. Any help would be greatly appreciated.

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

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

发布评论

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

评论(2

岁吢 2024-08-22 12:47:59

你明白这些标志的含义吗?链接器正在寻找库 SDL 和 SDLmain,它们是否安装在您的计算机上?

Do you understand the meaning of the flags? The linker is looking for the libraries SDL and SDLmain, are they setup on your machine?

怂人 2024-08-22 12:47:59

对我来说,解决方案如下:

g++ -c -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers  -I/Library/Frameworks/SDL_mixer.framework/Headers  -I/Library/Frameworks/SDL_ttf.framework/Headers  -I/Library/Frameworks/SDL_net.framework/Headers  -I/usr/local/include/SDL  -I/usr/local/include/ ./lesson20.cpp -o ./lesson20.o 

既然已经创建了目标文件,我们可以使用此解决方案:

g++ -L/usr/local/lib -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers -lSDLmain  -I/Library/Frameworks/SDL_mixer.framework/Headers  -I/Library/Frameworks/SDL_ttf.framework/Headers  -I/Library/Frameworks/SDL_net.framework/Headers  -framework SDL -framework SDL_image -framework Cocoa  -framework SDL_mixer -framework SDL_ttf -framework SDL_net -framework OpenGL lesson20.o  -o Lesson

此解决方案假设您已将 SDL_image、SDL_mixer、SDL_ttf 和 SDL_net 框架安装在“/Library/Frameworks/”目录中。

由于这很难手动尝试,并且解决方案有点混乱,因此最好简单地编写一个脚本来为您完成所有这些工作。

“-I”(大写 i)标志告诉编译器在哪里查找标头。 “-L”标志告诉编译器在哪里寻找库。 “-l”(小写 L)标志告诉编译器要使用哪些库。 “-framework”标志的行为基本上类似于“-l”(小写 L)标志。

For me the solution is as follows:

g++ -c -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers  -I/Library/Frameworks/SDL_mixer.framework/Headers  -I/Library/Frameworks/SDL_ttf.framework/Headers  -I/Library/Frameworks/SDL_net.framework/Headers  -I/usr/local/include/SDL  -I/usr/local/include/ ./lesson20.cpp -o ./lesson20.o 

Now that the object file has been created, we can use this solution:

g++ -L/usr/local/lib -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers -lSDLmain  -I/Library/Frameworks/SDL_mixer.framework/Headers  -I/Library/Frameworks/SDL_ttf.framework/Headers  -I/Library/Frameworks/SDL_net.framework/Headers  -framework SDL -framework SDL_image -framework Cocoa  -framework SDL_mixer -framework SDL_ttf -framework SDL_net -framework OpenGL lesson20.o  -o Lesson

This solution assumes that you have the SDL_image, SDL_mixer, SDL_ttf, and SDL_net frameworks installed in the '/Library/Frameworks/' directory.

Since this is difficult to attempt by hand, and the solution is a little messy, it's better to simply write a script to do all of this for you.

The '-I' (capital i) flag tells the compiler where to look for headers. The '-L' flag tells the compiler where to look for libraries. The '-l' (lower case L) flag tells the compiler which libraries to use. The '-framework' flag basically behaves like a '-l' (lower case L) flag.

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