Include boost's condition.hpp in realtime_publisher.h (ros ticket #4682)
Closed this issue · 11 comments
{{{
--- include/realtime_tools/realtime_publisher.h (revision 44224)
+++ include/realtime_tools/realtime_publisher.h (working copy)
@@ -43,6 +43,7 @@
#include <boost/utility.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
+#include <boost/thread/condition.hpp>
namespace realtime_tools {
}}}
Without this, the linker fails when compile ethercat_hardware in Release mode.
Example error:
{{{
CMakeFiles/motorconf.dir/src/motor_model.o: In function MotorModel::checkPublish()': motor_model.cpp:(.text+0x111e): undefined reference to
boost::condition_variable::notify_one()'
}}}
motor_model.cpp uses the realtime publisher, but does not use any boost condition variable directly.
{{{
/** \brief Publishes motor trace if delay time is up
*/
void MotorModel::checkPublish()
{
// ...
if ((publisher_==NULL) || (!publisher_->trylock()))
return;
publisher_->unlockAndPublish();
}
}}}
trac data:
- Owner: wim
- Reporter: dking
- Reported at: Tue Aug 31 13:34:58 2010
- URL: https://code.ros.org/trac/wg-ros-pkg/ticket/4682
[wim] A missing header should not result in a linking problem, but a compile problem.
We looked into this problem a while ago with master Josh and Ken, and what we found on one particular machine is that the linking flags were not passed through correctly. We found that when you initially run make you get different linking flags than when you run make after a make clean. Only after the make clean would you get the correct linking flags. There was a ticket created at that time against the build system.
Could you check if a make clean solves your problem too? If that is the case, could you check your linking flags before and after the make clean?
[gerkey] I think that #ros:2977 is the ticket that Wim's referring to.
[gerkey] Replying to [comment:3 gerkey]:
I think that #ros:2977 is the ticket that Wim's referring to.
I mean: ros:#2977
[blaise] I tried building from a fresh svn checkout and got this problem. I also tried doing a make clean. That did not solve my problem.
There is a missing include in realtime_publisher that should get fixed. (Currently Derek is adding the include to users of realtime_publisher to get them working, which is really the wrong thing to be doing.) I'll do some checking to make sure it actually does fix the runtime problem that is bothering me.
[blaise] I just verified that adding the include in realtime_publisher.h solves my realtime problem, and removing it again makes it go away.
Because of this, and because that include really should be there (as it uses boost condition variables), I have added the include to trunk in r44863.
I do not have any explanation for why this only shows up as a runtime error.
Because Jeremy is going to be working on Lucid for the PR2 very soon, it would be nice to get this fix released into cturtle as soon as possible. (That would also allow me to run from debs for the wge100 test stand.)
[wim] I merged the patch into the 1.2 branch, and am getting ready for a release.
[dking] There is no linking step in the compilation of the controllers is
because only dynamic libraries are created. They are dynamically
loaded by pluginlib when they are needed, this is when the linking step occurs.
In the situation, the undefined symbols are resolved. Any unresolvable symbols will cause an error.
I've simple package that uses realtime_publisher.hpp for a stand-alone executable instead of a plugin. When compile, I do indeed get an error:
{{{
CMakeFiles/realtime_publisher_test.dir/src/realtime_publisher_test.o: In function main': realtime_publisher_test.cpp:(.text+0x1301): undefined reference to
boost::condition_variable::notify_one()'
CMakeFiles/realtime_publisher_test.dir/src/realtime_publisher_test.o: In function realtime_tools::RealtimePublisher<std_msgs::Int32_<std::allocator<void> > >::~RealtimePublisher()': realtime_publisher_test.cpp:(.text._ZN14realtime_tools17RealtimePublisherIN8std_msgs6Int32_ISaIvEEEED1Ev[realtime_tools::RealtimePublisher<std_msgs::Int32_<std::allocator<void> > >::~RealtimePublisher()]+0x41): undefined reference to
boost::condition_variable::notify_one()'
CMakeFiles/realtime_publisher_test.dir/src/realtime_publisher_test.o: In function realtime_tools::RealtimePublisher<std_msgs::Int32_<std::allocator<void> > >::publishingLoop()': realtime_publisher_test.cpp:(.text._ZN14realtime_tools17RealtimePublisherIN8std_msgs6Int32_ISaIvEEEE14publishingLoopEv[realtime_tools::RealtimePublisher<std_msgs::Int32_<std::allocator<void> > >::publishingLoop()]+0xd2): undefined reference to
boost::condition_variable::wait(boost::unique_lockboost::mutex&)'
}}}
Here's the code:
{{{
#include
#include <realtime_tools/realtime_publisher.h>
#include "ros/ros.h"
#include "std_msgs/Int32.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "realtime_publisher_test");
ros::NodeHandle node;
ros::Rate loop_rate(10);
realtime_tools::RealtimePublisher<std_msgs::Int32> rtp(node, "count", 1, true);
int count = 0;
while(ros::ok())
{
if (rtp.trylock())
{
rtp.msg_.data = ++count;
rtp.unlockAndPublish();
}
ros::spinOnce();
loop_rate.sleep();
}
std::cerr << "Done!" << std::endl;
return 0;
}
}}}
I put the package the sandbox for cturtle.
{{{
https://code.ros.org/svn/wg-ros-pkg/branches/trunk_cturtle/sandbox/realtime_publisher_test
}}}
[wim] $ svn ci -m "release pr2_mechanims 1.2.2"
Adding rosdistro/cturtle.rosdistro
Transmitting file data .
Committed revision 1053.
[leibs] This does not appear to be released. It is now blocking lucid pr2s.
[wim] Talked to Jeremy, and the problem seems to be related to the switch from the old to the new release mechanism. This release was done with the old release mechanism.
[leibs] I released this properly. Should be going into the debs now.