I am having trouble with linking c-code with C++-code. The C++ code describes a ROS-node. I made a program that can read a compressed image-stream over udp with gstreamer in c-code. Each image-buffer calls a C++-method of the ROS-node, which effectively converts the gstreamer stream into a ROS image stream.
I organised it as such:
- udp_to_ros3.c file that describes gstreamer-functionality,
- ros_cpp.cpp file with class and wrapper for C-code to indirectly call class
- ros_cpp.o.so dynamic library compiled by catkin_make from ros_cpp.cpp (location: /home/edward/catkin_ws/devel/lib/)
- im_imageconv.h header of wrapper-code, used in ros_cpp.cpp and upd_to_ros3.c
I compiled upd_to_ros3.c to upd_to_ros3.o, and ros_cpp.o.so is compiled by catkin_make.
Now try to link it with: gcc -Wall -L/home/edward/catkin_ws/devel/lib/ udp_to_ros3.o -lros_cpp.o $(pkg-config --cflags --libs gstreamer-0.10) -lgstapp-0.10 -o udp_to_ros_image
I get the following errors:
/home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to cv::fastFree(void*)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
ros::init(int&, char**, std::basic_string, std::allocator > const&, unsigned int)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference toros::NodeHandle::~NodeHandle()' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
image_transport::ImageTransport::ImageTransport(ros::NodeHandle const&)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to ros::Time::now()' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
image_transport::Publisher::publish(boost::shared_ptr > const> const&) const' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference toimage_transport::ImageTransport::~ImageTransport()' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
ros::NodeHandle::NodeHandle(std::basic_string, std::allocator > const&, std::map, std::allocator >, std::basic_string, std::allocator >, std::less, std::allocator > >, std::allocator, std::allocator > const, std::basic_string, std::allocator > > > > const&)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to cv::waitKey(int)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
cv_bridge::CvImage::toImageMsg() const' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to ros::spinOnce()' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
cv::Mat::copySize(cv::Mat const&)' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to cv::Mat::deallocate()' /home/edward/catkin_ws/devel/lib//libros_cpp.o.so: undefined reference to
image_transport::ImageTransport::advertise(std::basic_string, std::allocator > const&, unsigned int, bool)' collect2: ld returned 1 exit status
I think it needs the ROS-headerfiles, but maybe also the libraries (?) as used by catkin to be able to link the two files. But even when I add -I/opt/ros/groovy/include/ros/ it still complains about undefined reference to ros:: things.
How to solve this the most pragmatic? Do I need to compile also the C-file within catkin CMakefile and link them together, or is there another way ?