Ask Your Question
2

Add MySQL to a ROS project?

asked 2012-04-24 17:01:02 -0500

gavinmachine gravatar image

updated 2014-01-28 17:12:05 -0500

ngrennan gravatar image

Hello,

How would I add MySQL functionality to a ROS project? I am running Ubuntu 11.04, I have MySQL installed, the .h is located at /usr/include/mysql/mysql.h.

Is there a way to include MySQL in the CMakeLists.txt file? Ideally, I would like to be able to do something like: #include <mysql.h> from my node.

Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
6

answered 2012-04-24 18:08:38 -0500

joq gravatar image

updated 2012-05-04 04:29:40 -0500

This may not be complete:

First, add <rosdep name="libmysqlclient-dev"/> to your manifest.xml.

Reference the file in your C++ sources using: #include <mysql/mysql.h>

Add something like this to your CmakeLists.txt:

find_package(MySql REQUIRED)
include_directories(${MYSQL_INCLUDE_DIRS})
add_definitions(${MYSQL_DEFINITIONS})

UPDATE: a library that depends on MySQL probably needs to export some link flags in its manifest.xml like this:

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

Normally, that would be done using pkg-config, but I don't see a .pc file for MySQL on Ubuntu Oneiric. You may have to figure out the correct lflags experimentally.

edit flag offensive delete link more

Comments

I think this is on the right track... To give more info: I am trying to execute MySQL queries in a package that I expose as a library to another node... the library package compiles just fine, it's when I try to compile the node that depends on the library that I get an error.

gavinmachine gravatar image gavinmachine  ( 2012-04-24 18:45:59 -0500 )edit

What is the error?

Dustin gravatar image Dustin  ( 2012-04-25 14:56:55 -0500 )edit

Dustin, say for example I attempt to call a library function from within the C++ of the node that is using the library, and the library function uses mysql_init(...), the compiler will throw "mysql_init(...) has not been defined." The library package itself compiles just fine, however.

gavinmachine gravatar image gavinmachine  ( 2012-04-26 06:56:07 -0500 )edit

Did you find a set of export lflags to solve that problem? Is it the compiler or the linker complaining about an unresolved mysql_init()?

joq gravatar image joq  ( 2012-04-26 08:57:11 -0500 )edit

Yep, adding the linker flag appeared to fix it! I added exactly what you posted above.

gavinmachine gravatar image gavinmachine  ( 2012-05-03 19:03:45 -0500 )edit
0

answered 2013-04-24 02:07:25 -0500

Hello, I have the same problem (the compiler say "mysql_init(...) has not been defined". I have done everything suggested,I added in manifest and CMakelist files the lines referred. I use ROS groovy and Ubuntu 12.04. I think there is something else that is needed to work. What exactly do I need to put in "name" field of "rosdep"? I see many choices. The "lflag" is always the same? Thanks.

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

1 follower

Stats

Asked: 2012-04-24 17:01:02 -0500

Seen: 1,544 times

Last updated: Apr 24 '13