Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing from source MacOS on M1 chip with Big Sur #8250

Closed
HansBambel opened this issue Jan 27, 2021 · 22 comments
Closed

Installing from source MacOS on M1 chip with Big Sur #8250

HansBambel opened this issue Jan 27, 2021 · 22 comments

Comments

@HansBambel
Copy link

HansBambel commented Jan 27, 2021

I am trying to use the D415 stereocamera via pyrealsense2, but I am struggling with installing the necessary libraries.
Since I am using not using an intel chip I found out that I need to install from source. I am following this tutorial, but I also need to follow this one for the Python-wrapper, right?
In point 3 in the latter link it says

Run the top level CMake command with the following additional flag -DBUILD_PYTHON_BINDINGS:bool=true:
mkdir build
cd build
cmake ../ -DBUILD_PYTHON_BINDINGS:bool=true
Note: To force compilation with a specific version on a system with both Python 2 and Python 3 installed, add the following flag to CMake command: -DPYTHON_EXECUTABLE=[full path to the exact python executable]

What is meant by the top level cmake command? Does this mean that I need to add this to the command that is given in the first link:

mkdir build && cd build
sudo xcode-select --reset
cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_OPENMP=false -DHWM_OVER_XU=false

so that the whole command will look like this:
cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_OPENMP=false -DHWM_OVER_XU=false -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/Users/kevin/opt/anaconda3/envs/p37/bin/python

If so, do I execute this command from the librealsense/build-folder or the librealsense/build/wrappers/python-folder?

I tried almost all combinations, but I receive the following error along with many warnings about deprecation:

CMake Error at /opt/homebrew/Cellar/cmake/3.19.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.19.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/opt/homebrew/Cellar/cmake/3.19.3/share/cmake/Modules/FindThreads.cmake:234 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
examples/measure/CMakeLists.txt:9 (find_package)

and in the librealsense/build/CMakeFiles/CmakeError.log:

CMakeError.log

The first error tells me that he can not find -lc++ and I don't know how do install that. Is it from a very old xcode version?

Any help would be greatly appreciated!

@HansBambel HansBambel changed the title Installing from source MacOS on M1 chip Installing from source MacOS on M1 chip with Big Sur Jan 27, 2021
@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jan 27, 2021

Hi @HansBambel We are aware of a couple of cases where difficulty has been encountered with installing librealsense on the new Apple Silicon M1 Mac models with Arm-based M1 processors instead of Intel processors that were launched in late 2020. Intel are looking into it. I have no update that I can provide at the time of writing this though.

#8090

The instructions regarding what constitutes the top level when installing the Python wrapper can be a little unclear. In general though, I see the CMake command initiated from the build folder, like you have done. This is also the method used in a CMake installation guide for the Python wrapper on MacOS that has been successful for some Mac users (though the guide dates to before the introduction of M1 processors).

#5275 (comment)

Another RealSense user's version of a guide for a successful MacOS Python wrapper installation with CMake is here:

#6402 (comment)

If you encounter an error referencing target.h when installing the Python wrapper on MacOS, the advice in the link below may also be helpful.

#6402 (comment)

Ultimately though, there are currently no guarantees that I can provide about installing on M1.

@HansBambel
Copy link
Author

Thank you for your answer. Sadly, it did not help me directly, but I managed to make work around the Could NOT find Threads (missing: Threads_FOUND) error by adding

set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)

which I found here.
Then CMake was able to run through correctly.
Sadly, then I run into the same issue as #8090 :(

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jan 27, 2021

I am sorry that you were not able to make progress with librealsense installation due to the x86 error aparently produced by the Arm-based M1 processor.

@HansBambel
Copy link
Author

Not your fault! I subscribed to the other issue and wait for a reply from intel then. In the meantime I have the luxury of using an intel-based MacBook as well.

@MartyG-RealSense
Copy link
Collaborator

Thanks very much for your understanding! I'm pleased to hear that you have an alternative Intel-based Mac available.

@jackjansen
Copy link

@MartyG-RealSense I fully share the understanding by others in this thread that supporting the new M1 architecture is not to be taken for granted:-) but still: it would be nice if we could get some indication of whether Intel has any plans for the foreseeable future, and/or whether the community can help.

Maybe it would be good to create a specific issue "Port librealsense2 to Apple M1", where we could follow easily?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jan 29, 2021

Hi @jackjansen As #8090 is where I direct RealSense users who are having this issue with M1 Macs, I have placed an Enhancement tag on that case as a reminder to keep it open. It can then be used as a focal point for posting comments about this issue from all affected users, fulfilling the same function as your own idea to create a specific issue.

At the moment, the situation status remains that Intel are looking into it.

@MartyG-RealSense
Copy link
Collaborator

Case closed due to #8090 being kept open as the central location to post Mac M1 comments.

@MartyG-RealSense
Copy link
Collaborator

Hi @HansBambel and @jackjansen A RealSense user shared the method that worked for them for building librealsense on their M1 Mac.

#8090 (comment)

@HansBambel
Copy link
Author

Thanks for the info! I might be able to try it out again on the M1 as well

adamnovak added a commit to vgteam/libvgio that referenced this issue Jun 3, 2021
To work around issues with building for M1 Macs where CMake will manage to not
find a Threads library
(IntelRealSense/librealsense#8250), just pretend we
have Threads with some sensible settings even when we don't.
@jalapatip
Copy link

jalapatip commented Jun 29, 2021

Hello @adamnovak and @HansBambel, I see that there are multiple CMakeLists.txt files in the package hierarchy. Which file do I make the changes to?

Also, I installed using 'brew install --build-from-source librealsense' as I was getting the following error with 'brew install'

'Error: librealsense: no bottle available!'

@HansBambel
Copy link
Author

That is a good question. I did not try this solution yet. Dynamized from the comment #8090 (comment) should know.

@jalapatip
Copy link

jalapatip commented Jun 29, 2021

That is a good question. I did not try this solution yet. Dynamized from the comment #8090 (comment) should know.

Thanks for the update! I will check with @dyamized.

@adamnovak
Copy link

@jalapatip You mean to work around the missing Threads CMake package? I think you need to make the changes to set the variables in all CMakeLists.txt files that say find_package(Threads REQUIRED) in them. This search ought to find all of them in this project.

@zarathustr
Copy link

zarathustr commented Aug 10, 2021

cmake .. -DBUILD_WITH_OPENMP=OFF -DENABLE_CCACHE=OFF -DCMAKE_HAVE_THREADS_LIBRARY=1 -DCMAKE_THREAD_LIBS_INIT="-lpthread" -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl

If you have linking problems of '-latomic', use the following cmake command:
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/Cellar/librealsense/2.48.0 -DBUILD_WITH_OPENMP=OFF -DENABLE_CCACHE=OFF -DCMAKE_HAVE_THREADS_LIBRARY=1 -DCMAKE_THREAD_LIBS_INIT="-lpthread" -DCMAKE_USE_WIN32_THREADS_INIT=0 -DTHREADS_PREFER_PTHREAD_FLAG=ON -DCMAKE_USE_PTHREADS_INIT=1 -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl -DCMAKE_CXX_FLAGS="-w" -DCMAKE_C_FLAGS="-w" -G Xcode

If you still get some errors of missing CMAKE_CXX_COMPILER or something, please do:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Delete the files in build directory and run cmake command again.

@MartyG-RealSense
Copy link
Collaborator

Thanks very much @zarathustr for sharing your knowledge . :)

@gschian0
Copy link

gschian0 commented Sep 2, 2021

I'm stuck at this same spot. after running both cmake comands.. When I run those commands and try to run either make -j2 or make install get this make: *** No rule to make target install'. Stop.`

@gschian0
Copy link

gschian0 commented Sep 2, 2021

on cmake command I get this response ... `CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

MACOSX_RPATH is not specified for the following targets:

realsense2-gl

This warning is for project developers. Use -Wno-dev to suppress it.`

@gschian0
Copy link

gschian0 commented Sep 6, 2021

ok... I'm making progress... i'm finding out now there is the cpuid.h file that is preventing the Xcode build. I'm not sure how to change it.
#if !(__x86_64__ || __i386__) #error this header is for x86 only #endif. and an error that says "This header is for x86 only"

@gschian0
Copy link

gschian0 commented Sep 6, 2021

in color-formats-converter.cpp this is causing the error
#include <cpuid.h> void cpuid(int info[4], int info_type) { __cpuid_count(info_type, 0, info[0], info[1], info[2], info[3]); } #endif

@gschian0
Copy link

gschian0 commented Sep 6, 2021

this looks like the culprit! I'm not sure how to fix it though...

`#if defined (ANDROID) || (defined (linux) && !defined (x86_64))

bool has_avx() { return false; }

#else

#ifdef _WIN32
#include <intrin.h>
#define cpuid(info, x) __cpuidex(info, x, 0)
#else
#include <cpuid.h>
void cpuid(int info[4], int info_type) {
__cpuid_count(info_type, 0, info[0], info[1], info[2], info[3]);
}
//#endif

bool has_avx()
{
int info[4];
cpuid(info, 0);
cpuid(info, 0x80000000);
return (info[2] & ((int)1 << 28)) != 0;
}

#endif
`
I'm not 100% sure on how to edit the cpuid.h file but in a search I did find a file that seems to grab an arm64 cpu id.

`/*

  • Copyright (c) 2017 Apple Inc. All rights reserved.
  • @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  • This file contains Original Code and/or Modifications of Original Code
  • as defined in and that are subject to the Apple Public Source License
  • Version 2.0 (the 'License'). You may not use this file except in
  • compliance with the License. The rights granted to you under the License
  • may not be used to create, or enable the creation or redistribution of,
  • unlawful or unlicensed copies of an Apple operating system, or to
  • circumvent, violate, or enable the circumvention or violation of, any
  • terms of an Apple operating system software license agreement.
  • Please obtain a copy of the License at
  • http:https://www.opensource.apple.com/apsl/ and read it before using this file.
  • The Original Code and all software distributed under the License are
  • distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  • EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  • INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  • Please see the License for the specific language governing rights and
  • limitations under the License.
  • @APPLE_OSREFERENCE_LICENSE_HEADER_END@
    */
    #ifndef ARM64_MACHINE_CPUID_H
    #define ARM64_MACHINE_CPUID_H

typedef struct {
uint64_t el0_not_implemented : 1,
el0_aarch64_only : 1,
el0_aarch32_and_64 : 1,
el1_not_implemented : 1,
el1_aarch64_only : 1,
el1_aarch32_and_64 : 1,
el2_not_implemented : 1,
el2_aarch64_only : 1,
el2_aarch32_and_64 : 1,
el3_not_implemented : 1,
el3_aarch64_only : 1,
el3_aarch32_and_64 : 1,
reserved : 52;
} arm_feature_bits_t;

/* Debug identification */

/* ID_AA64DFR0_EL1 */
typedef union {
struct {
uint64_t debug_arch_version : 4,
trace_extn_version : 4,
perf_extn_version : 4,
brps : 4,
reserved0 : 4,
wrps : 4,
reserved1 : 4,
ctx_cmps : 4,
reserved32 : 32;
} debug_feature;
uint64_t value;
} arm_cpuid_id_aa64dfr0_el1;

typedef struct {
uint32_t num_watchpoint_pairs;
uint32_t num_breakpoint_pairs;
} arm_debug_info_t;

#endif /* MACHINE_CPUID_H */
`

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Apr 24, 2022

Hi everyone, I just wanted to highlight that the brew install librealsense method of installing librealsense on Mac now lists support for MacOS Monterey and for Apple Silicon M1.

https://formulae.brew.sh/formula/librealsense

A highly detailed and up to date MacOS installation guide created by a RealSense user has also been published.

https://lightbuzz.com/realsense-macos/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants