ms-iot / ROSOnWindows

ROS on Windows Documentation Repository
https://aka.ms/ros/docs
MIT License
211 stars 48 forks source link

Problem compiling Gazebo plugin that uses the gazebo rendering Camera header #48

Open traversaro opened 5 years ago

traversaro commented 5 years ago

Describe the bug Compilation of a Gazebo plugin that uses the header <gazebo/rendering/Camera.hh> is not working.

To Reproduce After executing C:\opt\ros\melodic\x64\setup.bat and C:\opt\rosdeps\x64\share\gazebo-9\setup.bat, try to compile in Release a simple Gazebo plugin that includes <gazebo/rendering/Camera.hh> (based on http://gazebosim.org/tutorials/?tut=plugins_hello_world) https://gist.github.com/traversaro/8b47312cb53a1228aa59ead900522c17 :

git clone https://gist.github.com/traversaro/8b47312cb53a1228aa59ead900522c17 test_gazebo_rendering_camera
cd test_gazebo_rendering_camera
md build
cd build 
cmake -A x64 ..
cmake --build . --config Release

The last command results in the following error:

"C:\src\gazebo_plugin_tutorial\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\src\gazebo_plugin_tutorial\build\hello_world.vcxproj" (default target) (3) ->
(ClCompile target) ->
  C:\opt\rosdeps\x64\include\OGRE/Terrain/OgreTerrainPaging.h(33): fatal error C1083: Cannot open include file: 'OgrePagedWorldSection.h': No such file or directory [C:\src\gazebo_plugin_tutorial\build\hello_world.vcxproj]

    829 Warning(s)
    1 Error(s)

Time Elapsed 00:00:07.22

Uncommenting the following lines in the CMakeLists.txt:

# find_package(OGRE REQUIRED CONFIG)
# target_include_directories(hello_world PUBLIC ${OGRE_Paging_INCLUDE_DIRS})

the compilation works as expected. For some reason, this workaround is not necessary on Linux and macOS. Note that gazebo_pkg_ros has a similar workaround, but based on pkg-config: https://github.com/ros-simulation/gazebo_ros_pkgs/blob/melodic-devel/gazebo_plugins/CMakeLists.txt#L59 .

Expected behavior I would expect the plugin to compile correctly without workarounds, as it is the case on Linux and macOS .

Environment information:

C:\src\gazebo_plugin_tutorial\build>

ooeygui commented 5 years ago

Thanks for the report. @seanyen-msft, can you look into this?

seanyen commented 5 years ago

@traversaro Sorry for the delay on this.

It seems to me that gazebo-config.cmake is quite sensitive to what CMake files in current search path. For example, depending on FindOgre.cmake or OgreConfig.cmake is used, OGRE_xxx_INCLUDE_DIRS or OGRE-xxx_INCLUDE_DIRS is defined. However, gazebo-config.cmake only deals with OGRE_xxx_INCLUDE_DIRS.

For now, I will accommodate this by updating gazebo-config.cmake in our gazebo9 chocolatey package like this:

# Find OGRE
find_package(OGRE REQUIRED COMPONENTS Terrain Paging)
list(APPEND GAZEBO_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS})
list(APPEND GAZEBO_LIBRARIES ${OGRE_LIBRARIES})
# When including OGRE, also include the Terrain and Paging components
list(APPEND GAZEBO_INCLUDE_DIRS
  ${OGRE_Terrain_INCLUDE_DIRS}
  ${OGRE_Paging_INCLUDE_DIRS}
  ${OGRE-Terrain_INCLUDE_DIRS}
  ${OGRE-Paging_INCLUDE_DIRS})
list(APPEND GAZEBO_LIBRARIES
  ${OGRE_Terrain_LIBRARIES}
  ${OGRE_Paging_LIBRARIES}
  ${OGRE-Terrain_LIBRARIES}
  ${OGRE-Paging_LIBRARIES})

Let me know if it fixes your issue. Meanwhile, I will need to open a new discussion with Gazebo team on this.

seanyen commented 5 years ago

Adding conversation link in Gazebo side. https://bitbucket.org/osrf/gazebo/pull-requests/3090/