Ask Your Question
0

Using the MySQL database in ROS

asked 2019-07-30 13:31:36 -0500

victor654 gravatar image

updated 2019-07-30 14:00:59 -0500

jayess gravatar image

I tried to use the MYSQL database in ROS like this example but it doesn't work:

1. package.xml

<?xml version="1.0"?>
<package>
  <name>teste</name>
  <version>1.0.0</version>
  <description>The teste package</description>

  <maintainer email="joao@todo.todo">joao</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend >
  <build_depend>std_msgs</build_depend >
  <build_depend>cmake_modules</build_depend>
  <build_depend>libmysqlclient-dev</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend >
  <run_depend>std_msgs</run_depend >
  <run_depend>cmake_modules</run_depend>
  <run_depend>libmysqlclient-dev</run_depend> 


  <export>

    <cpp lflags="-lmysqlclient"/>
  </export>
</package>

2. CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(teste)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake-modules)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  MySqlClient REQUIRED
)

catkin_package(

)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${MYSQL_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME}_node  ${catkin_LIBRARIES} ${MYSQL_LIBRARIES} )

3. *The file "FindMySqlClient.cmake" in the folder "cmake-modules"*

IF (MYSQL_INCLUDE_DIR)
  SET(MYSQL_FIND_QUIETLY TRUE)
ENDIF (MYSQL_INCLUDE_DIR)

FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
  /usr/local/include/mysql
  /usr/include/mysql
)

SET(MYSQL_NAMES mysqlclient mysqlclient_r)
FIND_LIBRARY(MYSQL_LIBRARY
  NAMES ${MYSQL_NAMES}
  PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu/
  PATH_SUFFIXES mysql
)

IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
  SET(MYSQL_FOUND TRUE)
  SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
  SET(MYSQL_FOUND FALSE)
  SET( MYSQL_LIBRARIES )
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)

IF (MYSQL_FOUND)
  IF (NOT MYSQL_FIND_QUIETLY)
    MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
  ENDIF (NOT MYSQL_FIND_QUIETLY)
ELSE (MYSQL_FOUND)
  IF (MYSQL_FIND_REQUIRED)
    MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
    MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
  ENDIF (MYSQL_FIND_REQUIRED)
ENDIF (MYSQL_FOUND)

MARK_AS_ADVANCED(
  MYSQL_LIBRARY
  MYSQL_INCLUDE_DIR
  )

message error:

-- Could not find the required component 'MySqlClient'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "MySqlClient" with
  any of the following names:
    MySqlClientConfig.cmake
    mysqlclient-config.cmake
edit retag flag offensive close merge delete

Comments

The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found

Just to check have you tried this?

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2019-07-31 05:06:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-07-31 16:28:38 -0500

allenh1 gravatar image

In the post you reference, they explicitly find MySQL.

find_package(MySqlClient REQUIRED)

include_directories(${MYSQL_INCLUDE_DIRS})

However, in your example, you lumped it in as something catkin should look for.

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  MySqlClient REQUIRED
)

I think it should work if you just separate the find_package(MySqlClient REQUIRED) from the catkin components, since it is not a catkin component.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-07-30 13:30:32 -0500

Seen: 37 times

Last updated: Jul 31