深入浅出Android makefile(5)--BUILD_HOST_EXECUTABLE

本文深入探讨Android makefile中BUILD_HOST_EXECUTABLE的使用,揭示其在构建主机可执行文件过程中的步骤和作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上文我们讲完LOCAL_STATIC_LIBRARIES,下面我们就一步步来梳理下。BUILD_HOST_EXECUTABLE


一、 初识 BUILD_HOST_EXECUTABLE
我们先看BUILD_HOST_EXECUTABLE的定义:
build/core/config.mk:BUILD_HOST_EXECUTABLE:= $(BUILD_SYSTEM)/host_executable.mk
展开即build/core/host_executable.mk

二、  host_executable.mk
我们先看看host_executable.mk文件的注释:
###########################################################
## Standard rules for building an executable file.
##
## Additional inputs from base_rules.make:
## None.
########################################################### 
注释中明确的说明了,这是个编译可执行文件的makefile,附加的输入来源于 base_rules.make

LOCAL_IS_HOST_MODULE := true      
明确指出了LOCAL_IS_HOST_MODULE 为真,我们在做LOCAL_PATH分析时,多次使用到该变量,当时我们是估计它肯定是为真,但是没有找到其具体的定义位置,看来就是此处了。

ifeq ($(strip $(LOCAL_MODULE_CLASS)),)
LOCAL_MODULE_CLASS := EXECUTABLES
endif 
因为模块的初始化部分调用了include $(CLEAR_VARS),所以$(LOCAL_MODULE_CLASS)的值肯定为空,此处为其赋值为EXECUTABLES。此变量也是用在intermediates-dir-for函数中。

ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),)
LOCAL_MODULE_SUFFIX := $(HOST_EXECUTABLE_SUFFIX)
endif 
同理$(LOCAL_MODULE_CLASS)的值肯定为空,因为这里是要编译成可执行文件,linux上可执行文件是没有后缀的,换句话说,在此处 $(HOST_EXECUTABLE_SUFFIX)应该为空,该变量尚未初始化,所以必定为空。

下面又include了一个文件,include $(BUILD_SYSTEM)/binary.mk
但是打开这个文件,好家伙,600多行,怎么分析,不过看来大部分都是一些公共函数的定义。
我们先不管这个文件,继续下面分析。

$(LOCAL_BUILT_MODULE): $(all_objects) $(all_libraries)
     $(transform-host-o-to-executable)
     $(PRIVATE_POST_PROCESS_COMMAND) 
紧 接着定义了一个目标$(LOCAL_BUILT_MODULE),这个目标依赖于$(all_objects)和$(all_libraries),执行 两个操作:$(transform-host-o-to-executable)和 $(PRIVATE_POST_PROCESS_COMMAND)

首 先,我们先猜测下$(LOCAL_BUILT_MODULE)目标的值,因为LOCAL_IS_HOST_MODULE = true、LOCAL_MODULE_CLASS := EXECUTABLES它肯定是要放在out/host/linux-x86/obj/EXECUTABLES目录下,而LOCAL_MODULE = acp,故肯定是在刚才的目录下创建acp_intermediates文件夹,而$(LOCAL_BUILT_MODULE)的值估计就是: out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp 。下面我们就一步步分析下$(LOCAL_BUILT_MODULE)

三、 LOCAL_BUILT_MODULE
根据host_executable.mk文件开始处的注释,我们首先去查看下base_rules.make,我们发现在base_rules.make中有LOCAL_BUILT_MODULE变量的定义:
LOCAL_BUILT_MODULE := $(built_module_path)/$(LOCAL_BUILT_MODULE_STEM)

$(built_module_path)的定义又来源于:
wang@ubuntu:~$ ls /usr/lib/x86_64-linux-gnu/libpthread.so* /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/x86_64-linux-gnu/libpthread.so.0 wang@ubuntu:~$ sudo usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] file ... wang@ubuntu:~$ apt install libc6-dev glibc-source E: 无法打开锁文件 /var/lib/dpkg/lock-frontend - open (13: 权限不够) E: 无法获取 dpkg 前端锁 (/var/lib/dpkg/lock-frontend),请查看您是否正以 root 用户运行? wang@ubuntu:~$ cd ~/dog_ws wang@ubuntu:~/dog_ws$ rm -rf build devel # 彻底清理 wang@ubuntu:~/dog_ws$ catkin_make clean Base path: /home/wang/dog_ws Source space: /home/wang/dog_ws/src Build space: /home/wang/dog_ws/build Devel space: /home/wang/dog_ws/devel Install space: /home/wang/dog_ws/install #### #### Running command: "cmake /home/wang/dog_ws/src -DCATKIN_DEVEL_PREFIX=/home/wang/dog_ws/devel -DCMAKE_INSTALL_PREFIX=/home/wang/dog_ws/install -G Unix Makefiles" in "/home/wang/dog_ws/build" #### -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - 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 -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/wang/dog_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/wang/dog_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - dog_motion -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'dog_motion' -- ==> add_subdirectory(dog_motion) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy CMake Error at dog_motion/CMakeLists.txt:51 (add_xacro_files): Unknown CMake command "add_xacro_files". -- Configuring incomplete, errors occurred! See also "/home/wang/dog_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/wang/dog_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed wang@ubuntu:~/dog_ws$ catkin_make -DCMAKE_VERBOSE_MAKEFILE=ON # 启用详细日志 Base path: /home/wang/dog_ws Source space: /home/wang/dog_ws/src Build space: /home/wang/dog_ws/build Devel space: /home/wang/dog_ws/devel Install space: /home/wang/dog_ws/install #### #### Running command: "cmake /home/wang/dog_ws/src -DCMAKE_VERBOSE_MAKEFILE=ON -DCATKIN_DEVEL_PREFIX=/home/wang/dog_ws/devel -DCMAKE_INSTALL_PREFIX=/home/wang/dog_ws/install -G Unix Makefiles" in "/home/wang/dog_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/wang/dog_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/wang/dog_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - dog_motion -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'dog_motion' -- ==> add_subdirectory(dog_motion) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy CMake Error at dog_motion/CMakeLists.txt:51 (add_xacro_files): Unknown CMake command "add_xacro_files". -- Configuring incomplete, errors occurred! See also "/home/wang/dog_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/wang/dog_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed wang@ubuntu:~/dog_ws$
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值