ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are (at least) two issues here (both of which are - strictly speaking - actually not very ROS specific):

  1. compiling C code with a C++ compiler
  2. C++ name mangling

re 1): as you discovered, renaming a file with C code doesn't necessarily make it (valid) C++, hence the need for the compiler flags. Warnings like deprecated conversion are exactly what one would expect.

re 2): linking probably fails because C++ mangles names. Linker is looking for ?Fi_i@@YAHH@Z, mfg library exports int Fi_i(int bar). Compiling C as C++ is most likely the cause.

Suggestion: treat the library you got from the mfg as just another system dependency.

Use the normal make, (sudo) make install procedure to install the mfg lib and headers into /usr/local (or wherever it installs), like you already did before you "add(ed) ROS stuff". Then either - as you do now - hard-code the location of the headers and library in your CMakeLists.txt (not recommended), or write a minimal FindAAIO.cmake (or whatever you name it) that searches for the library and headers at CMake configuration time (highly recommended).

Up to here everything is actually non ROS-specific: this is a normal CMake workflow.

For your ROS node(s), just #include <..> the necessary headers from the mfg library into your C++ sources, but make sure they already do something like:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

This basically tells a C++ compiler to not mangle the names for any symbols declared inside those guards. I'd be surprised if the mfg library's headers don't already do this, but do check. This avoids the linker errors you encountered earlier.

Ideally your ROS node(s) would now be just a 'thin wrapper' around some AAIO library functions.