Closed MotorCityCobra closed 2 years ago
CMake doesn't add dependencies transitively, so you need to add_dependencies
on GLFW as well as mujoco::mujoco
.
~In other news, I think there's something a bit broken with our CMake setup since I'm setting missing MuJoCo symbols. Still investigating.~ EDIT: My bad, I forgot target_link_libraries
.
@saran-t
Thank you for the reply.
This works for you?
Is there a problem with my CMakeLists.txt? I thought I already have what you recommend.
For GLFW I did include_directories(mujoco/build/_deps/glfw-src/include/GLFW)
. I don't know how to add it with add dependencies
.
I've tried a few variations and I get the same error as in the original post.
I've been trying to do this for a few days. I'm having to include_directories
for quite a few things to avoid uitools.h: No such file or directory
and array_safety.h: No such file or directory
. After that I still get all the undefined errors. I did the install, last part of the cmake build. Should I try to add these to the CMakeLists.txt in the base mujoco directory of the repo before building and installing?
I'd prefer to have a clear answer either way, that I can bring the working library into a CMakeLists.txt or I can't. Maybe it's something coming in the future?
array_safety.h
and uitools.h
aren't currently officially part of MuJoCo itself, rather they're shipped as part of our sample applications. This may change in the near future, but in the meantime if your codebase needs these two headers you should copy and incorporate them into your own project.
Also, you shouldn't need include_directories
, only target_dependencies
should suffice. And you still need to add a dependency on GLFW as I mentioned above.
Are you actually using the GUI? If not then you shouldn't need uitools.h
...
only
target_dependencies
should suffice. And you still need to add a dependency on GLFW as I mentioned above.
I assume you mean add_dependencies
for glfw
.
I ended up installing glfw by cloning the glfw repo and building from source. I included it in my CMakeLists.txt with the code below.
find_package(glfw3 REQUIRED)
find_package(GSL REQUIRED)
link_libraries(GSL::gsl)
file(GLOB SOURCE_FILES mujoco_gym.cpp)
#CMAKE_PROJECT_NAME is from 'project(mujoco_gym)' on the second line of this script
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries (
${CMAKE_PROJECT_NAME}
${TORCH_LIBRARIES}
${GSL_LIBRARIES}
${mujoco_LIBRARIES}
glfw
)
The glfw undefinded
errors are gone.
I think I only have ui
errors now
/usr/bin/ld: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o: in function `loadmodel()':
mujoco_gym.cpp:(.text+0xa9ac): undefined reference to `uiModify'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xa9d3): undefined reference to `uiModify'
/usr/bin/ld: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o: in function `uiEvent(mjuiState_*)':
mujoco_gym.cpp:(.text+0xb1f4): undefined reference to `uiModify'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xb218): undefined reference to `uiModify'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xba01): undefined reference to `uiModify'
/usr/bin/ld: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o:mujoco_gym.cpp:(.text+0xba64): more undefined references to `uiModify' follow
/usr/bin/ld: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o: in function `init()':
mujoco_gym.cpp:(.text+0xd6e9): undefined reference to `uiFontScale'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xd761): undefined reference to `uiSetCallback'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xd9e8): undefined reference to `uiModify'
/usr/bin/ld: mujoco_gym.cpp:(.text+0xda0f): undefined reference to `uiModify'
/usr/bin/ld: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o: in function `main':
mujoco_gym.cpp:(.text+0xdb47): undefined reference to `uiClearCallback'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/mujoco_gym.dir/build.make:109: mujoco_gym] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mujoco_gym.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
When you place uitools.h
and uitools.c
into your own project, you either need to add it in the sources list of your binary/library target, or put them into a dedicated library and target_link_libraries
to that.
where can I find the file of uitools.h and uitools.c
These makefiles are old and unsupported. You can fix them and send a PR or we can just delete them. @saran-t has been wanting to delete them for a while...
ok, Thank you very much
I built and installed MuJoCo from source on my Linux machine. I am able to include mujoco in my C++ and it looks like not every part of mujoco I try to use throws an error but many do.
Here is my CMakeLists.txt
$cmake ..
completes without errors butcmake --build .
causes these errorsMy C++ file is one from the sample directory in the repo. It's large and could be any sample .cc file in the repo so I am not including.
I know MuJoCo installed on my machine in various paths under /usr/local and I have included every path I can think of from the mujoco repo I have downloaded so it's not clear to me why I can't include the library and build with cmake.