Environment
- OS Version: 20.04
- RTX 4090
- ROS noetic
- gazebo-11
- CUDA 12.2
- In this specific case: math-6
Description
Hello there. I am working on a Simulation of a radar sensor using ROS and gazebo. For the acceleration of some calculations I want to use CUDA. CUDA-code and non-CUDA code are seperated in different files. But both of them contain thesame header file because of gazebo specifc data types that are passed to the kernels. While compiling I got the following error message:
/usr/include/ignition/math6/gz/math/graph/Graph.hh: In member function ‘EdgeType& ignition::math::v6::graph::Graph<V, E, EdgeType>::LinkEdge(const EdgeType&)’:
/usr/include/ignition/math6/gz/math/graph/Graph.hh:249:67: error: expected ‘;’ before ‘}’ token
249 | for (auto const &v : {edgeVertices.first, edgeVertices.second})
| ^
| ;
/usr/include/ignition/math6/gz/math/graph/Graph.hh:266:67: error: expected ‘;’ before ‘}’ token
266 | for (auto const &v : {edgeVertices.first, edgeVertices.second})
| ^
| ;
/usr/include/ignition/math6/gz/math/graph/Graph.hh: In member function ‘bool ignition::math::v6::graph::Graph<V, E, EdgeType>::RemoveEdge(const EdgeId&)’:
/usr/include/ignition/math6/gz/math/graph/Graph.hh:614:67: error: expected ‘;’ before ‘}’ token
614 | for (auto const &v : {edgeVertices.first, edgeVertices.second})
I think NVCC has problems with the syntax {edgeVertices.first, edgeVertices.second} in Graph.hh.
Steps to reproduce
- Software as mentioned above
- The following configuration in CMakeLists.txt:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CUDA_NVCC_FLAGS "-arch=compute_89" CACHE STRING "nvcc flags" FORCE)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}; -std=c++17 --expt-relaxed-constexpr")
set(CUDA_NVCC_EXECUTABLE "/usr/local/cuda-12.2/bin/nvcc")
set(CMAKE_CUDA_COMPILER "${CUDA_NVCC_EXECUTABLE}")
set(CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
set(LIB_TYPE STATIC)
add_library(somelibrary SHARED src/test.cpp)
target_include_directories(somelibrary PUBLIC ${GAZEBO_INCLUDE_DIRS})
target_link_libraries(somelibrary ${GAZEBO_LIBRARIES})
cuda_add_library(cuda_lib ${LIB_TYPE} src/test.cu OPTIONS -Xcompiler -fPIC)
target_include_directories(cuda_lib PUBLIC ${CUDA_INCLUDE_DIRS})
target_link_libraries(cuda_lib
${catkin_LIBRARIES}
${CUDA_LIBRARIES}
somelibrary
)
add_executable(Testexe src/test.cpp)
add_dependencies(somelibrary ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(Testexe ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(Testexe somelibrary cuda_lib)
Output
I am not sure why this error occurs, becuse gcc has no problems compiling my non-CUDA code where math-6 is also included.
It might be a faulty CMakeLists.txt or a bug in NVCC itself.
Possible solution?
I “fixed” the problem by updating Grph.hh. I know it is not the best and recomandable way but in my case it works.
std::vector<decltype(edgeVertices.first)>temp = {edgeVertices.first, edgeVertices.second};
for (auto const &v : temp)
{
if (this->vertices.find(v) == this->vertices.end())
return EdgeType::NullEdge;
}
Is there any other possibility to fix this Problem?