How to solve 'undefined reference to `ros::init' on Groovy?
I use ROS groovy on ubuntu 12.04 64 bits.
I try to write the simplest program.
I run:
roscd
cd ../src
catkin_create_pkg sam_hello roscpp
roscd sam_hello
src/sam_hello_src1.cpp:
#include <ros/ros.h>
int main(int argc,char **argv)
{
ros::init(argc,argv, "sam_hello_node");
ros::spin();
return 0;
}
Then I edit CMakeLists.txt,add a line:
add_executable(sam_hello_node src/sam_hello_src1.cpp)
Then I try to make:
roscd
cd ..
catkin_make
It shows:
sam@sam:~/code/ros_groovy$ catkin_make
Base path: /home/sam/code/ros_groovy
Source space: /home/sam/code/ros_groovy/src
Build space: /home/sam/code/ros_groovy/build
Devel space: /home/sam/code/ros_groovy/devel
Install space: /home/sam/code/ros_groovy/install
####
#### Running command: "make cmake_check_build_system" in "/home/sam/code/ros_groovy/build"
####
####
#### Running command: "make -j4 -l4" in "/home/sam/code/ros_groovy/build"
####
Scanning dependencies of target sam_hello_node
[100%] Building CXX object sam_hello/CMakeFiles/sam_hello_node.dir/src/sam_hello_src1.cpp.o
Linking CXX executable /home/sam/code/ros_groovy/devel/lib/sam_hello/sam_hello_node
CMakeFiles/sam_hello_node.dir/src/sam_hello_src1.cpp.o: In function `main':
sam_hello_src1.cpp:(.text+0x46): undefined reference to `ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
sam_hello_src1.cpp:(.text+0x63): undefined reference to `ros::spin()'
collect2: ld 回傳 1
make[2]: *** [/home/sam/code/ros_groovy/devel/lib/sam_hello/sam_hello_node] Error 1
make[1]: *** [sam_hello/CMakeFiles/sam_hello_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
sam@sam:~/code/ros_groovy$
How to solve it?
Thank you~
---The following is the process that I setup groovy environments---
Commands:
source /opt/ros/groovy/setup.sh
mkdir -p ~/code/ros_groovy/src
cd ~/code/ros_groovy/src
catkin_init_workspace
cd ~/code/ros_groovy/
catkin_make
echo 'source $HOME/code/ros_groovy/devel/setup.bash' >> ~/.bashrc
source devel/setup.bash
Setting process:
sam@sam:~$ source /opt/ros/groovy/setup.sh
sam@sam:~$ mkdir -p ~/code/ros_groovy/src
sam@sam:~$ cd ~/code/ros_groovy/src
sam@sam:~/code/ros_groovy/src$ catkin_init_workspace
Creating symlink "/home/sam/code/ros_groovy/src/CMakeLists.txt" pointing to "/opt/ros/groovy/share/catkin/cmake/toplevel.cmake"
sam@sam:~/code/ros_groovy/src$ cd ~/code/ros_groovy/
sam@sam:~/code/ros_groovy$ catkin_make
Base path: /home/sam/code/ros_groovy
Source space: /home/sam/code/ros_groovy/src
Build space: /home/sam/code/ros_groovy/build
Devel space: /home/sam/code/ros_groovy/devel
Install space: /home/sam/code/ros_groovy/install
####
#### Running command: "cmake /home/sam/code/ros_groovy/src -DCATKIN_DEVEL_PREFIX=/home/sam/code/ros_groovy/devel -DCMAKE_INSTALL_PREFIX=/home/sam/code/ros_groovy/install" in "/home/sam/code/ros_groovy/build"
####
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /home/sam/code/ros_groovy/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
-- This workspace overlays: /opt/ros/groovy
-- Found PythonInterp: /usr/bin/python ...