Skip to main content

Hey, fellow Mac devs! I assume you landed on this page trying to figure out how to make the Intel RealSense camera work on macOS. You’ve most probably followed that discussion on GitHub. In this tutorial, I will provide a step-by-step guide to building the RealSense SDK for macOS, and I’ll also give you pre-compiled binaries for Apple Silicon and Intel chips.

RealSense + macOS ≠ ❤

Intel RealSense is a state-of-the-art family of depth cameras. Depth cameras allow your apps to “see” the world in 3D. How? Combining a traditional RGB video camera with an Infrared emitter, RealSense understands both the color and the physical location of each point! Intel has managed to manufacture high-precision yet affordable cameras for various applications (e.g., robotics, scanning, body-tracking, and more). I own more than ten of these cuties, and I particularly love the D455 model.

To their honor, Intel has open-sourced the official RealSense SDK, allowing developers to tinker and experiment with the C++ code.

Problem 1: Apple Silicon and Intel chips

I love the RealSense SDK because it’s cross-platform: it supports Ubuntu, Windows, Android, and macOS. However, since Apple transitioned to its new Apple Silicon chipsets, RealSense has found it hard to keep up.

Today, most Mac developers need to develop universal binaries: single binary files that run on both Intel (x86) and Apple Silicon (ARM) processors. The RealSense installation via brew is not such a binary. In this guide, we are going to develop purely universal RealSense binaries.

Problem 2: macOS 12 Monterey

A second major issue is the lack of support for the latest version of Apple’s desktop operating system: macOS Monterey (version 12). According to Intel, RealSense officially supports macOS High Sierra only – an operating system released in 2017!

In this tutorial, we are going to build the RealSense SDK to support macOS Big Sur (version 11) and Monterey (version 12). At the end of the article, I’m also including a link to download the prebuilt binaries.

Build RealSense for macOS

You are now aware of the problems we are going to solve. So, without further ado, let’s get to the build process. Many thanks to the RealSense developers who commented on GitHub and pointed us in the right direction.

Looking for a Python version, instead? Then, check out pyrealsense2 by Florian Bruggisser. Florian has created a handy shell script to automate the build process for Python.

Prerequisites

To build RealSense, you need to update your macOS computer to the latest version, which is macOS Monterey 12.3.1. Before starting, install the following software tools:

With the developer tools in place, install the OpenSSL library and the XCode command-line tools.

xcode-select --install
brew install openssl

1) Build libusb

RealSense cameras are (literally) powered by a USB-3 port. As a result, the SDK relies on the popular libusb library to manage the serial bus connection. libusb comes pre-installed on your Mac; however, it’s either an x86 or ARM binary. In our scenario, we need universal binaries, so we have to build libusb from source. To do so:

libusb XCode project

In XCode, go to ProductScheme and select libusb from the drop-down list. Then, select ProductSchemeEdit Scheme… Under the Run panel in the Info tab, set Build Configuration to Release.

libusb build configuration

Then, select the libusb project and the libusb target and navigate to the General tab. Set the Deployment Target value to 11. That means we are building libusb with Big Sur support, too.

libusb deployment target

Next, go to the Build Settings tab and set the Architectures value to Standard Architectures (Apple Silicon, Intel) – $(ARCH_STANDARD).

libusb architecture

Finally, go to ProductBuild or just click Cmd + B to build libusb.

When XCode finishes, open the build folder in Finder (ProductShow Build Folder in Finder).

Open ProductsRelease and launch a Terminal in that folder. You should see a file named libusb-1.0.0.dylib. Stay with me here, as we are going to remove the symbolic links of that binary. This way, we’ll be able to reference it from other binaries located next to it – instead of searching for it in a specific location.

install_name_tool -id @loader_path/libusb-1.0.0.dylib libusb-1.0.0.dylib

You may see a couple of warnings informing you that you are changing the signature of the file. That’s OK. It’s exactly what we want to do 🙂

2) Build librealsense

Moving on, it’s time to build the RealSense SDK for macOS. First, we’ll clone the GitHub repository and switch to the latest RealSense release (currently version 2.50.0). Next, open your Terminal to a location of your choice and type the following commands:

git clone https://github.com/IntelRealSense/librealsense.git
git checkout tags/v2.50.0

IF USING VERSION 2.49.0: Navigate to the root folder of the repository, open the file src → proc → color-formats-converter.cpp, and append the following in line 21: || defined(__aarch64__).

While in the librealsense repository folder, we’ll create a build folder and reset XCode:

mkdir build && cd build
sudo xcode-select --reset

Now, we’ll use CMake to create an XCode project:

cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_THREAD_LIBS_INIT="-lpthread" \
-DCMAKE_BUILD_TYPE=RELEASE \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_EXAMPLES=false \
-DBUILD_WITH_OPENMP=false \
-DHWM_OVER_XU=false \
-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl \
-G Xcode

Notice what we did there? First, we set the target architecture to universal by specifying both the arm64 and x86_64 variants. We also linked the thread library to avoid common CMake errors.

Hit Return and wait for XCode to build the project. Upon completion, the build folder of the RealSense repository should contain a file named librealsense2.xcodeproj. Open that file using XCode.

librealsense XCode project

Just like we did for libusb earlier, go to ProductScheme and select realsense2 from the drop-down list. Then, select ProductSchemeEdit Scheme… Under the Run panel in the Info tab, set Build Configuration to Release.

librealsense build configuration

Don’t forget backward compatibility! In your Targets section, select realsense2. Under the General tab, change the Deployment Target to 11 to support Big Sur.

librealsense deployment target

The tricky part begins. Move to the Build Settings tab and find Header Search Paths. That is the section we provide the external C/C++ header files our project relies on. We’ll instruct the compiler to search for our custom version of libusb instead of the built-in one. Find the default libusb location and replace it with the repository’s header folder location. In my case, it’s:

/Users/vangos/Documents/GitHub/libusb/libusb
librealsense libusb headers

Then, go to the Other Linker Flags section and select Release. That’s where we link our binary with the external dependencies. Find the default libusb location and replace it with the absolute path to the custom build folder. In my case, it is:

/Users/vangos/Library/Developer/Xcode/DerivedData/libusb-xyz/Build/Products/Release/libusb-1.0.0.dylib
librealsense libusb linker

Ready? Click Cmd + B to build the project. You may grab a cup of coffee since the process takes quite some time. When XCode finishes building the library, you should see the RealSense target under the Products folder.

As for the last step, we need to remove the symbolic links to have the RealSense binary next to our primary executable. Reveal librealsense2.2.50.0.dylib in Finder and open a Terminal there. Type:

install_name_tool -id @loader_path/librealsense2.2.50.0.dylib librealsense2.2.50.0.dylib

This is it! You can now create your C++ program and link it to the RealSense binaries. The binary even works with Unity apps. Hooray!

If you’ve reached that far, I assume you know how to develop, compile, and run apps on macOS. Teaching you how to do that is outside the scope of this tutorial, but let my team know if you need help.

3) Run as admin [Monterey]

Starting macOS Monterey, RealSense applications need elevated privileges to run properly. As a result, you need to run the app as an admin.

If your app is a C++ executable, simply run:

sudo ./MyProgram

If you developed a GUI app, you need to right-click your .app file and select Show Package Contents. That’s because GUI apps are nothing but specifically-structured folders. So, go to Contents → MacOS and run your main executable:

sudo ./MyApp
RealSense macOS app contents

You can run your RealSense app without admin privileges if using Big Sur.

Enable Root User

If you are tired of typing “sudo” all the time, you can enable the root user on your Mac (or, God mode). Here’s how to do that:

  1. Choose Apple menu → System Preferences, then click Users & Groups (or Accounts).
  2. Click the lock icon, then enter an administrator name and password.
  3. Click Login Options.
  4. Click Join (or Edit).
  5. Click Open Directory Utility.
  6. Click the lock icon in the Directory Utility window, then enter an administrator name and password.
  7. From the menu bar in Directory Utility:
    • Choose Edit → Enable Root User, then enter the password that you want to use for the root user.
    • Or choose Edit → Disable Root User.

When the root user is enabled, you have the privileges of the root user only while logged in as the root user.

  1. Choose Apple menu → Log Out to log out of your current user account.
  2. At the login window, log in with the user name “root” and the password you created for the root user.
    If the login window is a list of users, click Other, then log in.
macOS root user

Remember to disable the root user after completing your task.

Results

Your RealSense apps should run perfectly fine on macOS if you’ve followed the above steps. Notice how smoother the 60 or 90 frame rates seem in the M1 chipsets! Here’s the result on my M1 Mac Mini:

RealSense running on macOS Monterey

Body tracking

LightBuzz has been using RealSense to develop skeleton tracking applications and games. Our team has created the world’s best body-tracking SDK, and RealSense is a first-class citizen. Check it out!

Precompiled portable binaries

Tired of spending all that time compiling third-party libraries? Not familiar with C++ and CMake? Worry not! Our team has put together the precompiled portable C++ binaries so that you can use them in your apps right away. Click the button below to download.

Download binaries

Summary

In this guide, we built a single universal RealSense binary to support macOS Big Sure and Monterey on both Apple Silicon and Intel chipsets.

If you liked this post, do me a favor and share it with your friends and colleagues. ‘Til the next time, keep coding!

Vangos Pterneas

Vangos Pterneas is a software engineer, book author, and award-winning Microsoft Most Valuable Professional (2014-2019). Since 2012, Vangos has been helping Fortune-500 companies and ambitious startups create demanding motion-tracking applications. He's obsessed with analyzing and modeling every aspect of human motion using AI and Maths. Vangos shares his passion by regularly publishing articles and open-source projects to help and inspire fellow developers.

35 Comments

  • Konrad says:

    This does not work for me. I run monterey 12.4 and the prebuilt binaries yield “zsh: exec format error”, as in they seem to be built for a different architecture.

    Do I need to build the files from scratch but set to 12.4?

  • Hi Konrad! That’s right, you’ll need to build from scratch.

  • Konrad says:

    Actually, of course it gives that error – it’s a linking library, and I’m a fool. But I am quite curious as to how you got Unity to run with it. I’d appreciate any followups

    • To run RealSense in Unity, you also need to remove the symbolic links from the C++ binaries, so Unity can load the files from the executable’s path.

  • Konrad says:

    Thank you for replying, Vangos. I have one last question for now: Do you know any good resources for how to actually build my apps using this library? (I have a LiDAR L515). The documentation on github seems quite overwhelming and there’s not a lot about mac. I am a complete beginner/amateur and just looking for where to start.

    Essentially, the step from acquiring these 2 binaries (librealsense2.2.50.0.dylib and libusb-1.0.0.dylib, which I now managed to do using your very handy guide, thanks!) to building a simple application using either simple c++ code or including it in a Unity project – I don’t know where to find this information. Everywhere I look is either Windows, Linux, and/or seem to imply that I’m supposed to have way more files – headers and such – which weren’t produced in this guide.

    A bit long-winded, but if you know any good place to start I’d be super grateful. Cheers.

    • Hi Konrad. This guide is not “producing” header files because it’s compiling the library. Header files are not “produced” during the compilation process; there are already there. You only need the header files when importing the library into a new project. The header files tell C++ what the available API calls are.

      I don’t have a Mac-specific C++ guide. If you are a beginner, I strongly recommend using Unity on Windows, where it is much easier to run and deploy RealSense apps. There are built-in demos, and the process is straightforward.

      If you truly need Mac support, familiarize yourself with modern C++ and XCode before jumping to RealSense development. For example:

      • Start by creating simpler C++ programs.
      • Then, learn how to import external libraries and consume their APIs into your main app.
      • Finally, build and import RealSense into your project.

      There are no shortcuts in C++ development. It’s going to be a challenging process with a steep learning curve, but it’ll pay higher dividends in the long run 🙂

  • Shinya says:

    Hi, I am trying librealsense with Unity in my new M1 Max MacBook Pro and can’t get that working.
    None of self-built libraries from your instructions, pre-built binaries from you or even binaries from Homebrew is working with Unity integration.
    Because you stated like the binaries should work with Unity I must miss something.
    I am using “Intel.RealSense.unitypackage”, copy “librealsense2.2.50.0.dylib” and “libusb-1.0.0.dylib” into Plugins folder which includes Intel.RealSense.dll.
    Unity gives the error as,
    DllNotFoundException: realsense2 assembly: type: member:(null)

    Btw, realsenseviewer which installed via Homebrew is correctly working.

    I will be really appreciated if you could shed some light!

    • Hi Shinya! Making any C++ binary compatible with Unity3D for macOS is a little trickier than using the .so files directly. The recommended practice is converting the .so binaries into a .bundle file and referencing that bundle instead. Here are some reference links to get you started:

      Unity documentation
      Example project

      In short, you still need the produced binaries, but you need to wrap them into a bundle.

    • Alexis MATTON says:

      Hi Shinya, I also really need to use the librealsense in Unity with a M1 MacBook Pro. If you manage to make it function correctly that would be greatly appreciated to share it. Thanks you very much.

    • Shinya says:

      Sorry for replying this super late!
      Finally I made T265 work excluding dylib from Unity. Unity integration seems to use librealsense binaries which is installed via HomeBrew this case. I made sure that I got the same error by uninstalling librealsense from HomeBrew and re-installing librealsense with HomeBrew solved the problem.
      Today I tried D435 and found that is still not working. I should carefully follow this tutorial again!

  • Javier says:

    After finishing the guide and tried to compile the rs-hello-realsense.cpp example and I get this error. I am not sure what is missing.

    fatal error: ‘librealsense2/rs.hpp’ file not found

    • Hi Javier. That means your executable can’t find the RealSense header files. Before building, you need to provide the location of the RealSense headers in the Header Search Paths of your executable project.

  • France says:

    hello! does it still work for mac m1 ? i have the macos ventura 13.0.1 version

  • Mingxin Zhang says:

    Hello! I would like to ask if this method can work on the M2 Mac? I’m using an M2 MacBook Air with Ventura 13.3 and following all above steps. I have almost done but the RealSense target did not appear under the Products folder.

  • Mingxin Zhang says:

    Thank you for your reply, Vangos. There’s no error appears during the build process but a lot of warnings… Does this products folder refer to the products in the build folder under libusb?

    • Hi Mingxin. In XCode, you can select Product -> Show Build Folder in Finder to ensure there’s a built binary there.

    • Mingxin Zhang says:

      I have checked Show build folder (or Show Derived Data folder) for both realsense2 and libusb, and ensured that there’s no RealSense target. In the build folder of the libusb, there are two folders (intermidiates.noindex and Products. In the Products folder there’s only a Release.). In the derived data folder of realsense2, the files and folders are: Index.noindex, info.plist, Logs, OpenQuickly-ReferencedFrameworks.index-v1, scm.plist, SymbolCache, TextIndex, XCBuildData.

    • Should be under Release.

    • Mingxin Zhang says:

      The Release folder there are: libusb-1.0.0.dylib, libusb-1.0.0.dylib.dSYM, stress, stress.dSYM, usr. Still not find the binary…

    • If your target is libusb, the contents should include the libusb dylib. Switch targets to see the corresponding release folder.

  • Hasan says:

    When building on Ventura do we follow the same steps?

    Do we still choose 11 for the developer target?

    ” || defined(__aarch64__)” is not in the file mentioned in the latest versions of librealsense, do we still need to add it?

    As far as I understand we are instructed to create a build dir within the build dir, but when I run “cmake ..” it gives me an error because the cmake config file is in the root dir, am I doing something wrong?

    Thanks in advance

    • Hi Hasan. Yes, the process is the same in Ventura.

      I believe you may skip the __aarch64__ flag if build a RealSense version > 2.49. It seems like the __APPLE__ flag is included instead.

      Regarding the build folder, there should not be 2 folders named build. There should only be one (inside the repository root). Just delete the nested build folder and you should be good to go.

  • Hasan says:

    Hello,

    Thanks for the reply, I followed the steps again, but now it doesn’t even build. It looks like the header files are not being properly referenced even though I directly copied the path names from Finder.

    https://www.youtube.com/watch?v=5cEB-5q8JoI

    https://gist.github.com/HasanTheSyrian/74153a0322e91c69c33fc93418a42fdc

    Thanks in advance

    • Hi Hasan. We haven’t built the latest RealSense version (2.53) since they entirely removed Mac support. If we find a solution with v2.53, we’ll update the article accordingly.

  • Luca says:

    Hi, I followed this tutorial to build the librealsense library in my Mac air M1.
    Now I would love to use it in python inside visual studio code but I don’t know hot to import it. I have tried to search for methods but currently I can’t find one that’s working.
    Could you help me please?

  • Mary says:

    I had this same issue as Mingxin when trying to build on an M1 running Ventura, though I’m not sure if it’s related to the OS or changes to the repo which is now at version 2.54.1. In the first place I don’t have a librealsense2.xcodeproj in the build folder that I made in my librealsense repo. Instead I have realsense2.xcodeproj. When building libusb, everything is as expected. But then when trying to build the realsense2 project, that’s where things deviate. In Xcode, the menu changes to Products -> Show Derived Data folder.

    I am able to find a .dylib file for the project, but mine is librealsense2.2.54.1.dylib to reflect the different release version.

    I’m not sure if this helps or not; the issue I’m running into when trying to run examples is “failed to set power state”. From the bit of research I’ve done this may still have to do with permissions, and I can run realsense-viewer with sudo, but still get a slew of errors that prevent me from actually visualizing anything. As others have noted, the camera works with Photobooth, and also the External In object in Videosync. So I’m guessing it is indeed a permissions issue. I’m also testing with both a D415 and D435i with identical results.

    I’ll try cloning 2.5.50 and see if that has better results.

    (By the way, thanks for this guide! Very useful information even if it hasn’t taken me all the way to the finish line yet)

    • Mary says:

      I see that you explicitly change to the 2.50 branch.. I missed that in my earlier attempt because I couldn’t build from the command line clone, like Hasan. I cloned the repo from Tower, which for some reason behaves differently and allows me to build both branches.

    • Mary says:

      Final update for now: I went through the process of cloning, linking, and building librealsense2 again, this time using the 2.5.50 release. Now instead of the issue I described above, I am getting a slew of linker errors:

      Link librealsense2.2.50.0.dylib
      Undefined symbol: _libusb_alloc_transfer
      Undefined symbol: _libusb_bulk_transfer
      [and so on… 26 libusb errors in all]

      I triple checked the paths I modified and everything matches the paths on my system, so I’m a bit stumped. Sharing in case anyone is also attempting to build on Ventura. I keep reading that it *should* work but I don’t know that I’ve seen anyone report that they’ve actually tried and succeeded.

    • soungno says:

      I too have the same problem.

      The build runs fine on Ventura, but

      When running realsense-viewer (handle-libusb.h:127) failed to claim usb interface: 0, error: RS2_USB_STATUS_ACCESS
      An error will occur.

      Did you ever find a workaround?

    • Louis says:

      same as you! No products file~

  • Tamas Kalman says:

    Hello,

    i downloaded the binaries, but I don’t see any realsense viewer in it o_O

    • Hi Tamas. Thanks for noting that — we removed it during the past few years without updating that paragraph. You can run the RealSense Viewer by installing it directly from Homebrew:

      brew install librealsense

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.