调试符号未从 Yocto 中生成的二进制文件中剥离

Debug symbols not stripped from resulting binaries in Yocto

背景

我正在尝试在 Yocto build 中构建自定义软件。软件由 CMake 构建。

以下是我的食谱 - customsoftware.bb:

SRCBRANCH = "master"
SRCREV = "master"

MY_SRC = "OMITTED"

SRC_URI = "${MY_SRC};branch=${SRCBRANCH}"

# libraries dependencies
DEPENDS += "boost"

S = "${WORKDIR}/git"
B = "${WORKDIR}/build"

PARALLEL_MAKE ?= "-j 1"

inherit cmake

# My CMake Options
EXTRA_OECMAKE+=" -DSOME_OPTION=ON"

# I want unix makefiles instead on ninja build
OECMAKE_GENERATOR="Unix Makefiles"

以下是我的 cmake 项目的简化版本 - CMakeLists.txt

请注意:为简洁起见,我省略了不相关的部分

cmake_minimum_required(VERSION 3.0.0)

#---------------------------------------------------------------------------------------
# set default build to release
#---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/dist/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)

set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES  ON)

if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
    message(FATAL_ERROR "
    ${BoldRed}Error:${ColourReset} In-source builds are not allowed. You should create separate directory for build files.
    ${Magenta}CMAKE_BINARY_DIR${ColourReset}(${CMAKE_SOURCE_DIR}) must be different from ${Magenta}CMAKE_SOURCE_DIR${ColourReset}(${CMAKE_BINARY_DIR})
    ")
endif ()

project(myapp)

find_package(Boost REQUIRED COMPONENTS thread) 

add_executable(${PROJECT_NAME}
  ${HEADERS}
  ${SOURCES}
)

target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

#Copy entire contents of dist/ to /opt/myapp
install(DIRECTORY ${CMAKE_BINARY_DIR}/dist/
    DESTINATION /opt/myapp
)

我已将食谱添加到图片中。

问题

当我运行 du -h tmp/work/.../<customsoftware>/build/dist/bin二进制大小是80MB。此外,部署到目标系统后二进制大小为 80MB。

更新

正如评论中所建议的那样,tmp/work/.../<customsoftware>/image 中的二进制文件未被删除。但是,tmp/work/.../<customsoftware>/packages-split 处的二进制文件被删除。

如果我在应用程序源中 运行 make - 不是通过配方和 yocto 外部 - 二进制大小为 1.7MB

问题

如果我没记错的话,OE 构建将从生成的二进制文件中删除调试符号。

为什么我的二进制文件仍然使用调试符号部署?我错过了什么?

如何确保仅部署剥离 - 发布类型 - 二进制文件?

明确指定包类型并继承 pkgconfig 解决了我的问题。更新的食谱:

SRCBRANCH = "master"
SRCREV = "master"

MY_SRC = "OMITTED"

SRC_URI = "${MY_SRC};branch=${SRCBRANCH}"

DEPENDS += "boost"

S = "${WORKDIR}/git"

PARALLEL_MAKE ?= "-j 1"

inherit pkgconfig cmake

EXTRA_OECMAKE+=" -DSOME_OPTION"
OECMAKE_GENERATOR="Unix Makefiles"

# Specify package types
PACKAGES = "${PN}-dbg ${PN}"


FILES_${PN}-dbg += "\
    <INSTALL_PATH>/.debug \
    "

FILES_${PN} += "\
    <INSTALL_PATH>/* \
    "

能否请您尝试看看这个简单的 Hello World 是否在您的环境中被剥离了?

食谱:

DESCRIPTION = "Simple helloworld cmake"
LICENSE = "MIT"
SECTION = "examples"
LIC_FILES_CHKSUM = 
"file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://CMakeLists.txt \
           file://helloworld.c"

S = "${WORKDIR}"

inherit cmake

EXTRA_OECMAKE = ""

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.10)
project(helloworld)
add_executable(helloworld helloworld.c)
install(TARGETS helloworld RUNTIME DESTINATION bin)

helloworld.c:

#include <stdio.h>

int main() {
  printf("Hello World Makefile from CMake!\n");
  return(0);
}

如果你不介意调试版本 你可以做到

OECMAKE_C_FLAGS_RELEASE += "-s"
OECMAKE_CXX_FLAGS_RELEASE += "-s"

它将删除您的二进制文件