开发者

Compiling SDL Games on Mac

开发者 https://www.devze.com 2022-12-14 19:58 出处:网络
I have a mac and I am trying to compile my projects. The standard on the wiki: g++ sdl.c开发者_运维技巧pp -lSDLmain -lSDL -framework Cocoa does not seem to be working it returns that it cannot find -l

I have a mac and I am trying to compile my projects. The standard on the wiki: g++ sdl.c开发者_运维技巧pp -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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消