lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
980 stars 388 forks source link

undefined reference to `lcm_create' #332

Closed Joechencc closed 4 years ago

Joechencc commented 4 years ago

Same applies to lcm_publish' andlcm_destory'. Where should I add lcm to Cmake?

CMakeFiles/pointcloudlistener.dir/src/pointcloudlistener.cpp.o: In function callback(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&)': pointcloudlistener.cpp:(.text+0x93a): undefined reference tolcm_create' pointcloudlistener.cpp:(.text+0xabc): undefined reference to lcm_publish' CMakeFiles/pointcloudlistener.dir/src/pointcloudlistener.cpp.o: In functionlcm::LCM::~LCM()': pointcloudlistener.cpp:(.text._ZN3lcm3LCMD2Ev[_ZN3lcm3LCMD5Ev]+0x91): undefined reference to `lcm_destroy' collect2: error: ld returned 1 exit status beginner_tutorials/CMakeFiles/pointcloudlistener.dir/build.make:384: recipe for target '/home/chaonew/catkin_ws/devel/lib/beginner_tutorials/pointcloudlistener' failed make[2]: [/home/chaonew/catkin_ws/devel/lib/beginner_tutorials/pointcloudlistener] Error 1 CMakeFiles/Makefile2:821: recipe for target 'beginner_tutorials/CMakeFiles/pointcloudlistener.dir/all' failed make[1]: [beginner_tutorials/CMakeFiles/pointcloudlistener.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2

Joechencc commented 4 years ago

Sorry, I fixed that, it is due to my target_link_library

add_executable(pointcloudlistener src/pointcloudlistener.cpp) target_link_libraries(pointcloudlistener ${catkin_LIBRARIES} ${LCM_LIBRARY}) add_dependencies( ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS} )

Joechencc commented 4 years ago

Fixed