Just beginning to learn ROS, I intend to enter the pit of robots. The reference textbook is "ROS and its human development practice". Hu Chunxu compiled Huazhang Science and Technology Product of Machinery Industry Press. I thought I could follow the steps in the book step by step, but too young to simple, the hard days of programmers have begun, specifically recorded as follows.
When learning the helloworld program of ROS, we found that the compiler of ROS actually uses cmake, which is a big head, and keeps reading and practicing. Recorded below, environment kubuntu 18.04 system, latest upgrade, directory / home/municationk/WORKM/cmake/t1
Two files, main.c
1 #include <stdio.h> 2 3 int main(int argc, char **argv) 4 { 5 printf("Hello world!\n"); 6 7 return 0; 8 }
CMakeList.txt file:
1 PROJECT (HELLO) 2 SET(SRC_LIST main.c) 3 MESSAGE(STATUS "This is BINARY dir" ${HELLO_BINARY_DIR}) 4 MESSAGE(STATUS "This is SOURCE dir" ${HELLO_SOURCE_DIR}) 5 ADD_EXECUTABLE(hello ${SRC_LIST})
Code Description: Line numbers are meant to make it easier to specify the code. They are not needed and cannot be entered.
Simple hello code, which is complex, is only to illustrate complex problems, so as not to be disturbed by the complexity of the code.
Code: Execute commands: Don't omit the following ".", meaning to execute cmake commands in the current directory
cmake .
After execution, generated in the current directory / home/municationk/WORKM/cmake/t1:
-rw-rw-r-- 1 municationk municationk 12596 8 month 4 15:55 CMakeCache.txt drwxrwxr-x 5 municationk municationk 4096 8 month 4 16:17 CMakeFiles -rw-rw-r-- 1 municationk municationk 1510 8 month 4 15:55 cmake_install.cmake -rw-rw-r-- 1 municationk municationk 188 8 month 4 16:18 CMakeLists.txt -rw-rw-r-- 1 municationk municationk 96 8 month 4 15:50 main.c -rw-rw-r-- 1 municationk municationk 4709 8 month 4 16:17 Makefile
Other files can be created without concern. Makefile files can be made with it.
Then proceed with the execution of the order:
make
municationk@developk:~/WORKM/cmake/t1$ make -- This is BINARY dir/home/municationk/WORKM/cmake/t1 -- This is SOURCE dir/home/municationk/WORKM/cmake/t1 -- Configuring done -- Generating done -- Build files have been written to: /home/municationk/WORKM/cmake/t1 [100%] Built target hello
As mentioned above, it is correct to have no errors up to 100%. At this time, the directory / home/municationk/WORKM/cmake/t1 generates:
-rw-rw-r-- 1 municationk municationk 12596 8 month 4 15:55 CMakeCache.txt drwxrwxr-x 5 municationk municationk 4096 8 month 4 16:29 CMakeFiles -rw-rw-r-- 1 municationk municationk 1510 8 month 4 15:55 cmake_install.cmake -rw-rw-r-- 1 municationk municationk 188 8 month 4 16:18 CMakeLists.txt -rwxrwxr-x 1 municationk municationk 8296 8 month 4 16:17 hello -rw-rw-r-- 1 municationk municationk 96 8 month 4 15:50 main.c -rw-rw-r-- 1 municationk municationk 4709 8 month 4 16:29 Makefile
Finally, execute the order: the result comes out.
.hello
municationk@developk:~/WORKM/cmake/t1$ ./hello
Hello world!