-
Notifications
You must be signed in to change notification settings - Fork 1k
Static linking support for the MuJoCo library #2693
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
base: main
Are you sure you want to change the base?
Static linking support for the MuJoCo library #2693
Conversation
A comment on |
Is this a bug? mujoco/cmake/MujocoOptions.cmake Line 107 in 35665c5
|
So it seems that there weren't any speedups at all compared to the prebuilt. mujoco/cmake/MujocoOptions.cmake Line 107 in 35665c5
which basically disabled LTO. Not sure why it did't work in the past, but I can now do that no problem. However, static linking will still be beneficial for those that don't want to move the shared library around and want things as a single executable. |
What is the error if you did not added |
CMake Error: install(EXPORT "mujoco" ...) includes target "mujoco" which requires target "lodepng" that is not in any export set. |
@traversaro So I'm currently trying to make a shared library using GCC. For some reason the library fails to link with the final program saying the symbols are missing (e. g., undefined reference to `mj_loadXML') and upon inspection with nm, I get this:
Do you by any chance know what needs to be done to make this work? It's clearly something to do with LTO but not sure what. It works fine when using CLANG. |
I think your problem may have something to do with this file: include/mujoco/mjexport.h Try defining |
Can you share the exact error and the gcc version you are using? |
|
Can you share also the execution arguments passed to |
It doesn't seem to be happening on the main branch. The ld command doesn't seem to be called explicitly |
Actually sorry again, I accidentally only compiled the library without linking, it is still happening and this includes the main branch. The command:
|
It's like it can't read the symbols in the file due to LTO, but this only happens with gcc, clang works. I'm not sure if I need to have anything else installed on my system to make this work |
If that happens in the main branch, could it make sense to have a separate issue for it, ideally with the full command required to reproduce the errors, the exact mujoco commit and the distro you are using? |
Sure, I'll open one. |
Alright, I don't think there's anything from my side to be done on this. I've tested on windows and linux and it works. Someone has to test for Mac @traversaro . |
This introduces changes to the CMake files to allow static linking.
This is linked to #2618.
Update: It seems that starting from the main branch, libraries can be used with LTO without problems. Originally (3.3.3), I had to disable it for the dynamic library, which then resulted in slightly larger performance by just statically linking (+8%) and way larger performance when statically linking and LTO (+33%). This no longer seems to be the problem and the performance is not different.
TODO
Test on:
Summary from #2618:
Benchmarks are steps per second (calls to
mj_step
) Results are 60-second mean +- standard err.Prebuilt shared library
Prebuilt baseline: 116432.93 +- 151.63
Static linking (GCC):
102460.48 +- 44.18
Shared library (CLANG):
113133.28 +- 75.63
Shared library (GCC):
can't compile, not related to this PR.
Shated library (MSVC):
90465.95 +- 207.61
Other configuration variables:
-DCMAKE_C_COMPILER:STRING=clang-14 # Only when using clang
-DCMAKE_CXX_COMPILER:STRING=clang++-14 # Only when using clang
-DMUJOCO_HARDEN:BOOL=ON # Only when using clang
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF
-DMUJOCO_BUILD_EXAMPLES:BOOL=OFF