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

Update integration with external mujoco library #2

Merged
merged 9 commits into from
Jan 9, 2025

Conversation

erlingrj
Copy link
Contributor

@erlingrj erlingrj commented Jan 5, 2025

I was struggling a bit to get it to compile and run on my Ubuntu24.04. It prompted some reading of Mujoco and CMake documentation. The Mujoco people recommend using their prebuilt binaries so I went with this, I have not tested it for macOS so I was hoping that you, Edward, could verify that it works.

For Ubuntu, this depends on merging lf-lang/lingua-franca#2454

README.md Outdated
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build .
sudo cmake --install .
sudo mkdir -p /opt/mujoco-3.2.6-linux-x86_64/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am installing to /opt which on Linux is a convention for manually installed packages

README.md Outdated Show resolved Hide resolved
src/include/mujoco.cmake Outdated Show resolved Hide resolved
@erlingrj erlingrj requested a review from edwardalee January 5, 2025 19:07
@erlingrj
Copy link
Contributor Author

erlingrj commented Jan 6, 2025

@edwardalee thanks for the feedback. I reverted to installing from source for both macOS and Ubuntu, but I install the library to /opt/mujoco instead of /usr/local. In my experience it is best practice to put manually installed packages in /opt. I have verified that this works both on Ubuntu 24.04 and macOS

Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installation procedure almost worked for me. Installation of MuJoCo succeeds, and compilation of src/MuJoCoBasicDemo succeeded, but running it fails:

$ bin/MuJoCoBasicDemo
dyld[79731]: Library not loaded: '@rpath/libmujoco.3.2.6.dylib'
 Referenced from: '/Users/eal/git/mujoco-c/bin/MuJoCoBasicDemo'
 Reason: tried: '/usr/local/lib/libmujoco.3.2.6.dylib' (no such file), '/usr/lib/libmujoco.3.2.6.dylib' (no such file)
Abort trap: 6

I think that /opt is not a place macOS will typically look. How do you get it to look there?
The following worked for me:

export DYLD_LIBRARY_PATH=/opt/mujoco/lib/:$DYLD_LIBRARY_PATH

I guess this needs to be put into a .bash_profile or .zprofile.

README.md Outdated Show resolved Hide resolved
@lhstrh
Copy link
Member

lhstrh commented Jan 7, 2025

I tried the instructions but mujoco failed to compile (Arch Linux):

referenced by /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../lib/Scrt1.o:(_start)
collect2: error: ld returned 1 exit status
make[2]: *** [simulate/CMakeFiles/simulate.dir/build.make:104: bin/simulate] Error 1
make[1]: *** [CMakeFiles/Makefile2:6886: simulate/CMakeFiles/simulate.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

@erlingrj
Copy link
Contributor Author

erlingrj commented Jan 7, 2025

This installation procedure almost worked for me. Installation of MuJoCo succeeds, and compilation of src/MuJoCoBasicDemo succeeded, but running it fails:

$ bin/MuJoCoBasicDemo
dyld[79731]: Library not loaded: '@rpath/libmujoco.3.2.6.dylib'
 Referenced from: '/Users/eal/git/mujoco-c/bin/MuJoCoBasicDemo'
 Reason: tried: '/usr/local/lib/libmujoco.3.2.6.dylib' (no such file), '/usr/lib/libmujoco.3.2.6.dylib' (no such file)
Abort trap: 6

I think that /opt is not a place macOS will typically look. How do you get it to look there? The following worked for me:

export DYLD_LIBRARY_PATH=/opt/mujoco/lib/:$DYLD_LIBRARY_PATH

I guess this needs to be put into a .bash_profile or .zprofile.

Did you try master of lingua-franca? I just merged a PR which should address this and where we don't need to set any environment variable

@erlingrj
Copy link
Contributor Author

erlingrj commented Jan 7, 2025

I tried the instructions but mujoco failed to compile (Arch Linux):

referenced by /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../lib/Scrt1.o:(_start)
collect2: error: ld returned 1 exit status
make[2]: *** [simulate/CMakeFiles/simulate.dir/build.make:104: bin/simulate] Error 1
make[1]: *** [CMakeFiles/Makefile2:6886: simulate/CMakeFiles/simulate.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Hm, we can compromise and build from source in the case of macOS and use prebuilt binaries for Linux. Can you instead try the new updated docs for Linux?

@erlingrj erlingrj requested a review from edwardalee January 8, 2025 18:23
Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@edwardalee edwardalee merged commit 0df6ce7 into main Jan 9, 2025
@edwardalee edwardalee deleted the update-cmake-and-docs branch January 9, 2025 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants