Can you figure out along make, cmake, makefile and CMakeLists.txt (package.xml) ?

Recently, i have met the make, cmak and makefile during learning the ROS (Robot Operating System). They make me dizzy. There are some idea to help you remeber them.

  1. gcc
    GNU Compiler Collection (gcc) is considered as a kind of editor. It can compile so many kinds of programming languges including C, C++, Objective-C, Fortran, Java and so on. If we only have one source file, we can compile it with gcc directly.
    However, if we have many source files needed to be compiled. You will find that this work are both chaoic and heavy. what should we do ?
    The make emerge as the times require.

  2. make
    The make is regarded as a smart batch processing tool and it cannot compile and link. However, it can compile and link indirectly by invoking orders set by the user in the makefile file.
    What is makefile file ?

  3. makefile
    if make is the chef , the makefile is the recipe. the chef cooks the dishes according to the recipes, while the make compiles depend on the makefile. the orders including invode the gcc (or other compiler) to compile some source files.
    When the workspace is simple, user can write it by hand, but it is hard to writer the makefile files by hand. What is more, it is needed to be modified in different platform. A new and powerful tool was born in the proper conditions.

  4. cmake
    The cmake can create a makefile file to be used by the make file. Of course, it is so powerful that it can be used on different platforms without modifying. However, how to generate the makefile ? the CMakeLists.txt needed

  5. CMakeList.txt (package.xml) [extension for robot operating system (ROS)]
    the compiler is the CMake in ROS, and the rules of compiling will be set in the CMakeLists,txt in the package. the file of CMakeLists.txt will generated in the process of the package is created by catkin order. We do not need to check the relevant instruction manuals and compile our own code with slight modifications.
    When you open the CMakeLists,txt file in the function package, find the following configuration items, remove the comments and modify them slightly:

	include_directories(include  ${catkin_INCLUDE_DIRS})

	add_executable(talker  src/talker.cpp)
	target_link_libraries(talker  ${catkin_LIBRARIES})
	add_dependencies(talker  ${PROJECT_NAME}_generate_messages_cpp)
    
	add_executable(listener  src/listener.cpp)
	target_link_libraries(listener  ${catkin_LIBRARIES})
	add_dependencies(talker  ${PROJECT_NAME}_generate_messages_cpp)
  • A. include_directories

  • B. add_executable
    used for setting compiling codes and executable file. the first parameter “talker” is the expected executable name that you want to get. The parameters “src/talker.cpp” is the source file that need to be compiled. If many source files needed to be compiled, list them one after another separated by space.

  • C. target_link_libraries
    Some functions need to use the system and the third party library files, You can link to the them by this way. the first parameter is the expected executable name that you want to get. behind it is the link libraries.

  • D. add_dependencies
    set the dependencies. some message type needed to be defined, the codes will generated during compiling the message type. If the executable file need the codes to run, the “add_dependencies” need to be used.

  1. The overall process is:
    the process of compiling and linking based on CMakeList file
  • 1. write the source codes, for example .c file.
  • 2. compile and generate the object file, like .o file.
  • 3. generate the excutable files using the linker to link the object file, like .exe file.
    If there are many source files, to compile them one by one, it is so heavy. so person design a kind of batch-processing program to compile the source files. it is the make tool.
    however, the rule file that the make need to obey is needed, so the programmer have to write the makefile file.
    For large project, to get the makefile is not eassy, so people begain to think and design another tool that can read all of the source files and generate makfile files automatic. So the cmake tool appeares that can output all kinds of makefile files and project files to help programmer to reduce the burden.
    But the question is that the CMakeList.txt file needed to be writed due to it is the rules that the camke will obey.
    You will find that when you solve the old problem, while the new question appears. it is the main cycle of life and science. the socity and techs will develop during this recycling.

1.undersatand the make/cmake/makefile/CMakeList in 5 seconds
2. the CMakeList.txt and package.xml in ROS
3. add_link_libraries/add_executable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值