-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Working on macOS
The quickstart is a cross platform template for all desktop platforms that will setup raylib automatically.
https://github.com/raylib-extras/raylib-quickstart
It works with many compilers on windows, linux and Mac OS. Works with makefiles, visual studio, and VSCode.
Simply follow the instructions in that link and you will be done, you do not need to use the rest of this document.
This guide has been written using the following software:
- OSX El Capitan (10.11.3)
- Xcode 7.2.1 (7C1002)
Homebrew build option tested on:
- macOS Big Sur (11.3.1)
- Xcode 12.5
Steps:
-
Get a Mac with OSX version 10.11.3.
-
Install Apple Developer Tools. Those tools include Xcode, in our case version 7.2.1.
-
Install raylib library
- If you don't want to build it yourself, install Homebrew by executing the following command in Terminal.app:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Once Homebrew is installed, run the following command in Terminal:
brew install raylib
- The raylib package installs a pkg-config file, which describes the necessary compilation and linker flags to use it with
yourgame
:
eval cc yourgame.c $(pkg-config --libs --cflags raylib) -o YourGame
- If the build fails, you may need to run the following command with the required frameworks
eval cc yourgame.c -framework IOKit -framework Cocoa -framework OpenGL $(pkg-config --libs --cflags raylib) -o YourGame
You may get an error, complaining that the pkg-config
command was not found. You can use brew install pkgconfig
to fix that. If you install pkgconfig after you have installed raylib with homebrew, you should reinstall raylib so that pkgconfig works correctly. Use in the terminal
brew reinstall raylib
NOTE: The raylib Homebrew package tracks the latest raylib release and as such can be out of date with what's in master. For active development, we suggest building the newest development snapshot instead.
- Download or Clone raylib from GitHub (https://github.com/raysan5/raylib).
raylib-master.zip
contains all required files: source code, examples, templates, games... - Decompress
raylib-master.zip
in some folder. In case of using Safari browser, it will be automatically decompressed. - From Terminal.app, access
raylib-master/src
directory:
cd raylib-master/src
- Compile raylib library using the following command from Terminal:
make PLATFORM=PLATFORM_DESKTOP
- If everything worked ok,
libraylib.a
should be created inraylib-master/src
folder.
- Add generated libraries (raylib) to Xcode project. This step can be automated with Xcode project template. If, for some reason, you want to do it manually, continue with these steps:
- Create a new Xcode project using
Command Line Tool
. Make sure selected language is C. - Once project created and open, Mouse click over the project main folder in the left project-navigation panel. It should appear
Build Phases
window, just enter and selectLink Binary With Libraries
. There you should add project libraries:- To add OpenGL: Click on and add OpenGL.framework
- You may also need to add these frameworks in the same way:
- CoreVideo.framework
- IOKit.framework
- Cocoa.framework
- To add raylib: Click on and
Add Other...
, look forlibraylib.a
file created previously, it should be in folderraylib-master/release/osx
(make sure library has been created in that folder). - Make sure Xcode finds
raylib.h
: Go toBuild Settings > Search Paths
and add raylib header folder (raylib-master/src
) toHeader Search Paths
- Make sure Xcode finds
libraylib.a
: Go toBuild Settings > Search Paths
and add raylib library folder (raylib-master/release/osx
) toLibrary Search Paths
.
- raylib should work correctly. To make sure, just go to official raylib page and check the different examples available. Just copy the code into
main.c
file and run it with Run button or ⌘R.
NOTES:
- It seems there is a problem with HiDPI displays, in that case, app Window appears smaller. Solution is just moving a bit the Window and it should get scaled automatically.
- Examples resources should be placed in the folder where Xcode generates the product.
Tutorial written by Aleix Rafegas and translated to English by Ray
Building statically means you can run this application on other machines with ease - users won't have to have any of the frameworks installed that are required. Also, this will work on mac's 10.9 and up.
- From the command line
export MACOSX_DEPLOYMENT_TARGET=10.9
- Install XCode tools (don't forget to then update the tools in the Mac App Store after!)
xcode-select --install
- Build raylib (Again, this is so the export line takes effect)
git clone https://github.com/raysan5/raylib.git
cd raylib/src
make
You may do the otool check with the file in raylib/src/libraylib.a here if you like. (LC_VERSION_MIN_MACOSX should be version 10.4), and we're good!
cp raylib/src/libraylib.a YOUR_PROJECTS_ROOT_FOLDER
- Build your project!
clang -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL libraylib.a my_app.c -o my_app
Note: If you are compiling a C project, you will need to make sure your compiler supports C 11 standards. With clang you can enable this by passing -std=c 11
, see https://clang.llvm.org/cxx_status.html for more details.
Check for warnings! This can tell you if a library you're linking to was not built for OSX 10.9, in which case you'll need to rebuild that too.
Check otool one last time for the LC_VERSION_MIN_MACOSX version:
otool -l my_app
Last thing, let me show you something cool:
otool -L my_app
This shows you everything your application links to. Basically, if anything is pointing to anything but /usr/lib/* or /System/Library/*, your application will throw an error if you run it on any other Mac. It's not portable. For example if it's linking to something in /usr/local/lib, or a relative folder, that would be bad. But after the above, you should be clear of dynamic dependencies!
mkdir standard.app/Contents
mkdir standard.app/Contents/MacOS
mkdir standard.app/Contents/Resources
touch standard.app/Contents/Info.plist
The app you just created, "my_app" should go in the MacOS folder.
mv my_app standard.app/Contents/MacOS
Info.plist should read like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>my_app</string>
</dict>
</plist>
See more fields you can add here: https://stackoverflow.com/questions/1596945/building-osx-app-bundle
Now you can double click on standard.app and it will run your application! Note that some things will be cached by the OS. If you want to refresh your application bundle run this:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f standard.app
This has a whole lot of potentially useful info on all the apps on your system, you can use this to determine if the version is correct I suppose:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump > dump.txt
Just search for your app in dump.txt.
You could just as easily do a zip I suppose, but DMGs are fashionable aren't they?
Here's a 32 megabyte dmg:
- Create the writeable dmg.
hdiutil create -size 32m -fs HFS -volname "My App" my_app_writeable.dmg
- Attach
my_app_writeable.dmg
. This should tell you something like/dev/disk3
or something. Make a note of that, you'll need it for the next step.
hdiutil attach my_app_writeable.dmg
- Drag your app into the dmg. Then run this, replacing
disk999
with whatever/dev/disk
was specified in the previous step.
hdiutil detach /dev/disk999
- Convert to
my_app.dmg
.
hdiutil convert my_app_writeable.dmg -format UDZO -o my_app.dmg
- Share it. Congratulations,
my_app.dmg
is ready to be sent to all your most trusted game critics.
www.raylib.com | itch.io | GitHub | Discord | YouTube
- Architecture
- Syntax analysis
- Data structures
- Enumerated types
- External dependencies
- GLFW dependency
- libc dependency
- Platforms and graphics
- Input system
- Default shader
- Custom shaders
- Coding conventions
- Integration with other libs
- Working on Windows
- Working on macOS
- Working on GNU Linux
- Working on Chrome OS
- Working on FreeBSD
- Working on Raspberry Pi
- Working for Android
- Working for Web (HTML5)
- Working on exaequOS Web Computer
- Creating Discord Activities
- Working anywhere with CMake
- CMake Build Options
- raylib templates: Get started easily
- How To: Quick C/C Setup in Visual Studio 2022, GCC or MinGW
- How To: C# Visual Studio Setup
- How To: VSCode
- How To: Eclipse
- How To: Sublime Text
- How To: Code::Blocks