using an external library: C versus C++ issue
I downloaded a vendor's library for accessing analog I/O ( http://www.rtd.com/software/CM/aAIO/a... ) on their motherboard ( http://www.rtd.com/PC104/CM/CMX32/CMX... ) and it works fine. I can compile the driver, install the driver, compile the library, compile the example usage code and run the example usage code that uses the library. It works like a charm. All the compiles use the command line "make" command. My problem is that I can't figure out how to get this exact same example code to compile in my catkin workspace and then add ROS code into it so I can publish the analog readings as ROS topics.
(Actually the link to the tarball above is old and the vendor emailed me a new version that is not on their website yet. Let me know if you would like me to get that corrected tarball to you.)
The example code I want to start with is "soft_trig.c" from the examples folder. I can copy that file into my catkin package, add it to the CMakeLists.txt, get it to compile as straight C code linked to the library without any ROS calls, and even execute it using rosrun just fine.
Here is my working CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(ros_aaio_node)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package(
)
include_directories(
~/aaio/include
${catkin_INCLUDE_DIRS}
)
link_directories(~/aaio/lib)
add_executable(ros_aaio_node src/soft_trig.c)
target_link_libraries(ros_aaio_node
rtd-aaio
${catkin_LIBRARIES}
)
So now I want to add ROS stuff to the file so I can publish data as ROS Topics. This is where I don't know what to do. I added
#include <ros/ros.h>
to the file and I got lots of compile errors. Lots of header files were not found.
It occurred to me that all my other ROS code was cpp files, not c files, so I renamed the file to soft_trig.cpp and changed the executable line in the CMakeLists.txt file too and I get a lot of different compile errors now. Tons of deprecated conversion warnings and several invalid conversion errors.
I saw some working code on another project where a coworker had been using a straight C compiled library with their ROS code and they used these two lines in their CMakeLists.txt:
set(CMAKE_C_FLAGS "-std=c99" )
set(CMAKE_CXX_FLAGS "-fpermissive")
So I tried that and all the compiler warnings and errors went away. But now I get a whole slew of undefined reference errors during linking.
Linking CXX executable ~/catkin_ws/devel/lib/ros_aaio_node/ros_aaio_node
CMakeFiles/ros_aaio_node.dir/src/soft_trig.cpp.o: In function `main':
soft_trig.cpp:(.text+0x851): undefined reference to `aAIO_Open(aAIO_Descriptor**, unsigned char)'
soft_trig.cpp:(.text+0x873): undefined reference to `aAIO_Return_Status(aAIO_Descriptor*, int, char*)'
soft_trig.cpp:(.text+0x8a0): undefined reference to `aAIO_Reset(aAIO_Descriptor*)'
soft_trig.cpp:(.text+0x8c2): undefined reference to `aAIO_Return_Status(aAIO_Descriptor*, int, char*)'
soft_trig.cpp:(.text+0x934): undefined reference to `aAIO_Install_ISR(aAIO_Descriptor*, void (*)(unsigned int), void (*)(unsigned int), void (*)(unsigned int), void (*)(unsigned int), void (*)(unsigned ...