Closed dtorre38 closed 1 year ago
When you say "run MuJoCo" do you mean that you just want to play around interactively with various models?
In that case you should just download the DMG containing the prebuilt binary from our Releases page.
Up-to-date quick start instructions are in the README which is displayed on the repo's landing page. Edit: also in our documentation
The mujoco app works, but that only provides basic functionality. I am referring to running my own models with my own functionality through the terminal. On an intel Mac it is easy to run mujoco and is just as described in the documentation, but it is not the same steps for arm based Macs. The same code will not run on mujoco on both machines and it requires several other steps as I mentioned above.
I'm still not clear on exactly what it is that you're asking. You can simulate your own models through the prebuilt binaries by drag-dropping your own XML file.
Are you writing your own C++ program that you want to link against MuJoCo? In that case you could either link against MuJoCo as a framework via -framework mujoco
(provided that you use -F
to set the correct path to mujoco.framework
) or you can just link against the .dylib
directly using the -l
flag, as you would any other dynamic library.
If you are a Python programmer the you just need to pip install mujoco
.
Also we aren't doing anything that's Intel or ARM specific. If you have something that works on an Intel machine it really should just work on an ARM machine too. What is it that you tried and couldn't get to work?
I am programming in C and linking MuJoCo as a framework. This worked fine for my intel Mac, but upon switching to M1 all files are broken. Even a simple case of running a C script linked with MuJoCo will no longer run. The test case is a C script that opens simulate and displays a cube.
To get this to run I have to place the following in the same folder as the run file, C script, and XML:
libglfw.3.3.dylib libmujoco.2.2.1.dylib
The run file contains the following lines (added spaces between each line for readability):
`reset
make -f makefile clean -C ../sample
make -f makefile -C ../sample
install_name_tool -change @rpath/mujoco.framework/Versions/A/libmujoco.2.2.1.dylib ~/Documents/mujoco-2.2.1/build/mujoco_macosARM/bin/libmujoco.2.2.1.dylib main
install_name_tool -change /opt/homebrew/opt/glfw/lib/libglfw.3.dylib ~/Documents/mujoco-2.2.1/build/mujoco_macosARM/bin/libglfw.3.3.dylib main
./main ../model/sample.xml
`
Where the makefile is:
`COMMON = -O2 -I../include -L../bin LDFLAGS = -lglfw.3.3 -lmujoco.2.2.1 CC = gcc ROOT = -o ../bin/main CFLAGS = -c -w
all: main_all
main_all: main.o (COMMON) (ROOT) main.o main.o: main.c (COMMON) $(CFLAGS) main.c clean: rm main.o `
This works, but is different from what is required to run on an Intel Mac. The differences are bolded. I'm sure that there is a simpler way to run mujoco on M1.
Can you provide more detail on what you mean when you say it doesn't run? What's the error?
The program does run, but it requires me to modify all my previous mujoco files as stated above. I have many mujoco projects and the process would be very tedious.
If possible could you reopen this thread? I was hoping to also get insight from the community.
You still haven't told us what the problem is other than "it doesn't work".
It's unlikely that you're going to get much help without providing more details... Most of our team (including myself) uses an M1 laptop as our daily drivers so it's not like this is a non-standard platform for us, but we can't help you without seeing the actual errors.
Thank you for reopening this thread. I apologize, I was under the assumption that there weren't many M1 users.
I have a feeling that my issues stem from my makefiles. In your transition from intel to M1 did you have to make any changes to your makefiles or CMakeLists.txt file to obtain functionality? My knowledge regarding CMakeLists.txt is rudimentary, so I modified a CMakeLists.txt file that I found in a mujoco folder. When I utilize it, it is not creating the makefile. Here is the CMakeLists.txt file:
`# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.16)
# INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
# Default to GLVND if available.
set(CMAKE_POLICY_DEFAULT_CMP0072 NEW)
# This line has to appear before 'PROJECT' in order to be able to disable incremental linking
set(MSVC_INCREMENTAL_DEFAULT ON)
project(test)
enable_language(C)
enable_language(CXX)
if(APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
endif()
# Check if we are building as standalone project.
set(SAMPLE_STANDALONE OFF)
set(_INSTALL_SAMPLES ON)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(SAMPLE_STANDALONE ON)
# If standalone, do not install the samples.
set(_INSTALL_SAMPLES OFF)
endif()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
link_directories(../lib/gsl)
if(SAMPLE_STANDALONE)
include(SampleOptions)
else()
enforce_mujoco_macosx_min_version()
endif()
include(SampleDependencies)
set(MUJOCO_SAMPLE_COMPILE_OPTIONS "${AVX_COMPILE_OPTIONS}" "${EXTRA_COMPILE_OPTIONS}")
set(MUJOCO_SAMPLE_LINK_OPTIONS "${EXTRA_LINK_OPTIONS}")
#set(CMAKE_C_FLAGS -w -Wno-implicit-function-declaration)
set(CMAKE_C_FLAGS -w)
set(ADD_LIBS -lgsl -lgslcblas -lm)
if(MUJOCO_HARDEN)
if(WIN32)
set(MUJOCO_SAMPLE_LINK_OPTIONS "${MUJOCO_SAMPLE_LINK_OPTIONS}" -Wl,/DYNAMICBASE)
else()
set(MUJOCO_SAMPLE_COMPILE_OPTIONS "${MUJOCO_SAMPLE_COMPILE_OPTIONS}" -fPIE)
if(APPLE)
set(MUJOCO_SAMPLE_LINK_OPTIONS "${MUJOCO_SAMPLE_LINK_OPTIONS}" -Wl,-pie)
else()
set(MUJOCO_SAMPLE_LINK_OPTIONS "${MUJOCO_SAMPLE_LINK_OPTIONS}" -pie)
endif()
endif()
endif()
# Build samples that require GLFW.
add_executable(main main.c)
target_compile_options(main PUBLIC ${MUJOCO_SAMPLE_COMPILE_OPTIONS})
target_link_libraries(
main
${ADD_LIBS}
mujoco::mujoco
glfw
Threads::Threads
)
target_link_options(main PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS})
# Do not install if macOS Bundles are created as RPATH is managed manually there.
if(APPLE AND MUJOCO_BUILD_MACOS_FRAMEWORKS)
set(_INSTALL_SAMPLES OFF)
endif()
if(_INSTALL_SAMPLES)
include(TargetAddRpath)
# Add support to RPATH for the samples.
target_add_rpath(
TARGETS
main
INSTALL_DIRECTORY
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
LIB_DIRS
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
DEPENDS
MUJOCO_ENABLE_RPATH
)
if(NOT MUJOCO_SAMPLES_USE_SYSTEM_GLFW)
# We downloaded GLFW. Depending if it is a static or shared LIBRARY we might
# need to install it.
get_target_property(MJ_GLFW_LIBRARY_TYPE glfw TYPE)
if(MJ_GLFW_LIBRARY_TYPE STREQUAL SHARED_LIBRARY)
install(
TARGETS glfw
EXPORT ${PROJECT_NAME}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT samples
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT samples
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT samples
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT samples
)
endif()
endif()
endif()
`
The error is as follows:
Can you try running cmake
with -G Ninja
? You might need to also brew install ninja
first.
I installed ninja and ran as you suggested. Now I'm getting this error:
I installed ninja and ran as you suggested. Now I'm getting this error:
I found this same error on a stack overflow post: https://stackoverflow.com/questions/73142302/ive-installed-a-library-into-my-usr-local-directory-i-would-now-like-to-inclu
I attempted to implement the suggested fix by adding the following line in the CMakeLists.txt file, but it did not work.
find_package(mujoco REQUIRED)
Completed a fresh install of MuJoCo 2.3.5 and attempted to run with a modified version of the Makefile.macos that comes in the sample folder (shown below). Unfortunately, the same error persists, MuJoCo cannot be found/linked:
ld: framework not found mujoco clang: error: linker command failed with exit code 1 (use -v to see invocation)
GLFWROOT ?= $(shell brew --prefix)
MUJOCOPATH ?= /Applications/MuJoCo.app/Contents/Frameworks
CFLAGS := -O2 -F$(MUJOCOPATH) -I$(GLFWROOT)/include -pthread
LDFLAGS := -L$(GLFWROOT)/lib -Wl,-rpath,$(MUJOCOPATH)
LDLIBS := -framework mujoco
all: main
main: main.c
gcc $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: clean
clean:
rm -f main
Found the fix thanks to #313. In the terminal, run the following once:
ln -s Versions/Current/libmujoco.2.3.5.dylib /Applications/MuJoCo.app/Contents/Frameworks/mu
joco.framework/mujoco
@saran-t mentioned that this issue was resolved with v.2.2.1 in #313, but that wasn't the case for me. I'm not sure how prevalent this issue is, but it might be worth looking into although there is a simple fix thanks to @coolvision.
This is the sample makefile that works:
GLFWROOT ?= $(shell brew --prefix)
MUJOCOPATH ?= /Applications/MuJoCo.app/Contents/Frameworks
CFLAGS := -O2 -F$(MUJOCOPATH) -I$(GLFWROOT)/include -pthread
LDFLAGS := -L$(GLFWROOT)/lib -Wl,-rpath,$(MUJOCOPATH)
LDLIBS := -framework mujoco -lglfw
all: main
main: main.c
gcc $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: clean
clean:
rm -f main
I am still unable to run via cmake. I will post once I get that working as CMakeLists.txt is the preferred method for MuJoCo.
Issue with CMakeLists.txt was due to skipping a step in building from source:
cmake --install .
Now the mujoco library can be found. This may have also influenced the previous error with the makefile.
Here is a working CMakeLists.txt file:
cmake_minimum_required(VERSION 3.16)
project(template)
# Append the project-specific cmake module path
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Set the C compiler flags to suppress warnings
set(CMAKE_C_FLAGS "-w -Wno-implicit-function-declaration")
# Find the Mujoco & GLFW3 packages
find_package(mujoco REQUIRED)
find_package(glfw3 REQUIRED)
# Create the main executable
add_executable(main main.c)
# Link libraries to the main executable
target_link_libraries(main mujoco::mujoco glfw)
Hi,
I'm a student and I'm trying to use MuJoCo for research.
I'm looking for some help with running mujoco on M1 Mac. Unfortunately there are no tutorials on the web.
I've tried modifying the CMakeLists.txt file to run a sample code, but I cannot get it to run. I found one method which works (on v2.2.1), but it is very convoluted. To run the sample code:
1) Place the following in the same folder: libglfw.3.3.dylib, libmujoco.2.2.1.dylib, and a "run" file which is structured as follows:
reset make -f makefile clean -C ../sample make -f makefile -C ../sample install_name_tool -change @rpath/mujoco.framework/Versions/A/libmujoco.2.2.1.dylib ~/Documents/mujoco-2.2.1/build/mujoco_macosARM/bin/libmujoco.2.2.1.dylib main install_name_tool -change /opt/homebrew/opt/glfw/lib/libglfw.3.dylib ~/Documents/mujoco-2.2.1/build/mujoco_macosARM/bin/libglfw.3.3.dylib main ./main ../model/sample.xml
and the makefile is as follows:
`COMMON = -O2 -I../include -L../bin LDFLAGS = -lglfw.3.3 -lmujoco.2.2.1 CC = gcc ROOT = -o ../bin/main CFLAGS = -c -w
all: main_all
main_all: main.o $(CC) $(COMMON) $(LDFLAGS) $(ROOT) main.o main.o: main.c $(CC) $(COMMON) $(CFLAGS) main.c clean: rm main.o `
2) Execute main file in terminal.
This method works, but it's not the most efficient. Has anyone else found an easy way to run MuJoCo on M1 Mac?