想要利用g++来封装一个最简单的talker和listener。我按照ros wiki的教程已经做好了ws、cmakelist等,并且能够通过rosrun成功运行。
但是在封装时,我在listener所在的src文件夹中打开终端,键入g++ -o listener listener.cpp -L. liblistener.so(已经能够编译生成liblistener.so文件和listener.o文件了)。结果不断报错,如下所示
/usr/bin/ld: /tmp/ccyEXvVs.o: in function `main':
listener.cpp:(.text+0x158): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
/usr/bin/ld: listener.cpp:(.text+0x51d): undefined reference to `ros::Rate::Rate(double)'
/usr/bin/ld: listener.cpp:(.text+0x522): undefined reference to `ros::ok()'
/usr/bin/ld: listener.cpp:(.text+0x5ce): undefined reference to `ros::spinOnce()'
/usr/bin/ld: listener.cpp:(.text+0x5dd): undefined reference to `ros::Rate::sleep()'
/usr/bin/ld: listener.cpp:(.text+0x5f6): undefined reference to `ros::Subscriber::~Subscriber()'
/usr/bin/ld: listener.cpp:(.text+0x605): undefined reference to `ros::Subscriber::~Subscriber()'
此前在生成.o和.so文件时,编译报错找不到头文件,我就给g++添加了ros/的搜索路径,于是就能生成了,现在想生成可执行文件却生成不了。