首页 > 解决方案 > 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不会被剥离。但是,二进制文件 attmp/work/.../<customsoftware>/packages-split被剥离。

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

问题

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

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

我怎样才能确保只部署了剥离 - 发布类型 - 二进制文件?

标签: cmakeyoctobitbakeopenembeddedrecipe

解决方案


您能否尝试看看这个简单的 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)

你好世界.c:

#include <stdio.h>

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

推荐阅读