如何将librt和libpthread链接到Yocto中的新层? [英] How do I link librt and libpthread to a new layer in Yocto?

查看:72
本文介绍了如何将librt和libpthread链接到Yocto中的新层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随后的问题
在哪里可以找到有关aarch64-poky-linux-的文档ld?

请忽略多组外部双引号.他们似乎有必要获得"StackOverflow";接受我的输入.
我的层是"meta-oca-so",其包是"oca".它的配方是oca_1.2.7.bb.
我修改了我的oca makefile"修复以前的链接器错误以及一些与之相关的错误无效的链接标志,现在我获得完整的29个"oca".a库链接在一起当我做"bitbake oca"时.更改链接时,我不必做任何清洁工作标志并重做"bitbake oca".
现在,当我执行"bitbake oca"操作时,错误消息为:

Please ignore sets of outer double-quotes. They seem necessary to get "StackOverflow" to accept my input.
My layer is "meta-oca-so", its package is "oca" and its recipe is oca_1.2.7.bb.
I revised my "oca makefile" to fix the previous and some linker errors to do with invalid link flags, and I'm now getting the full 29 "oca" .a libs to link together when I do "bitbake oca". I didn't have to do any clean while changing the link flags and redoing "bitbake oca".
Now when I do "bitbake oca", the error messages are:

~/Yocto/imx-yocto-bsp/build-wayland/tmp/work/aarch64-poky-linux/oca/1.2.7-r0/oca-1.2.7/Obj/linuxApp/Release/OcaProto
aarch64-poky-linux-ld: cannot find -lstdc++
aarch64-poky-linux-ld: cannot find -lrt
aarch64-poky-linux-ld: cannot find -lpthread
aarch64-poky-linux-ld: cannot find -ldns_sd

关注"librt"和"libpthread"在这个问题中,我将这些行添加到了我的" local.conf":

Focusing on "librt" and "libpthread" in this question, I added these lines to my "local.conf":

IMAGE_INSTALL_append=" librt"
TOOLCHAIN_TARGET_TASK_append=" librt"
IMAGE_INSTALL_append=" libpthread"
TOOLCHAIN_TARGET_TASK_append=" libpthread"

但是当我重命名"bitbake oca"时,它并没有清除其两个链接错误.

But it didn't clear its two link errors when I redid "bitbake oca".

当我尝试整体的"bitbake imx-image-multimedia"时,我收到这些讯息关于"librt":

When I tried the overall "bitbake imx-image-multimedia" I got these messages about "librt":

NOTE: Resolving any missing task queue dependencies
ERROR: Nothing RPROVIDES 'librt' (but /home/james/Yocto/imx-yocto-bsp/sources/meta-imx/meta-sdk/recipes-fsl/images/imx-image-multimedia.bb RDEPENDS on or otherwise requires it)
NOTE: Runtime target 'librt' is unbuildable, removing...
Missing or unbuildable dependency chain was: ['librt']
ERROR: Required build target 'imx-image-multimedia' has no buildable providers.
Missing or unbuildable dependency chain was: ['imx-image-multimedia', 'librt']

很难找到有关"rt"的更多信息.因为这两个字母的组合是在统计上不可能.

It's hard to find much info about "rt" because this two-letter combination is not statistically improbable.

类似地,当我注释掉两个"librt"时,来自"local.conf"的行并重试"bitbake imx-image-multimedia",我收到了有关"libpthread"的这些消息:

Similarly, when I commented-out the two "librt" lines from "local.conf" and retried "bitbake imx-image-multimedia", I got these messages about "libpthread":

ERROR: Nothing RPROVIDES 'libpthread' (but /home/james/Yocto/imx-yocto-bsp/sources/meta-imx/meta-sdk/recipes-fsl/images/imx-image-multimedia.bb RDEPENDS on or otherwise requires it)
NOTE: Runtime target 'libpthread' is unbuildable, removing...
Missing or unbuildable dependency chain was: ['libpthread']
ERROR: Required build target 'imx-image-multimedia' has no buildable providers.
Missing or unbuildable dependency chain was: ['imx-image-multimedia', 'libpthread']

如何获取"librt"和"libpthread"?
我需要每个都添加一个图层来构建它们吗?会有依赖地狱"吗?他们每个人都需要支持包的树吗?

How do I obtain "librt" and "libpthread"?
Do I need to add a layer each to build them? Will there be a "dependency hell" tree of supporting packages needed for each of them?

这里是相关的makefile组件,makeOCA.inc.共有63个"make"OCA项目中具有不同描述和不同级别的文件.它相当长,大约为1070行.我删节了非Linux系统的内容.我只关心linuxRelease.

Here's the relevant makefile component, makeOCA.inc. There are 63 "make" files of different descriptions and at different levels in the OCA project. It's pretty long, at ~1070 lines. I snipped the sections for non-Linux systems; I'm only concerned with linuxRelease here.

#  Project             : OCA
#  Module              : Multiple components
#  Description         : Include file for C / CPP makefiles.
#

################################################################################
# Environment variable checking
################################################################################
#
# If one of the variables below is not set,
# calling make will result in a "missing separator" error.
#
ifeq ($(CAP_HOME),)
  variable CAP_HOME is not set
else
  CAP_HOME := $(patsubst %/,%,$(subst \,/,$(CAP_HOME)))
endif

################################################################################
# Variables
################################################################################
ifeq ($(NAME_MKE),)
  NAME_MKE := makefileOCA
endif
ifeq ($(IGNORE_MAKE_ERRORS),Y)
  PREFIX := -@
else
  ifneq ($(DISPLAY_MAKE_CMDS),Y)
    PREFIX := @
  endif
endif
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
#
# Only set variables when the makefile is called with an actual target
# (not a phony one).
#
ifneq ($(PLATFORM),)
  ifneq ($(RELEASE),)

    # Project home
    PRJ_HOME := $(CAP_HOME)

    # Src home
    SRC_HOME := $(PRJ_HOME)/Src

    # Include directories
    ifneq ($(USRINC),)
    INCDIRS := $(subst ; ,;,$(subst \,/,.;\
        $(SRC_HOME)/inc;\
        $(SRC_HOME)/lib/inc;\
        $(SRC_HOME)/common;\
        $(SRC_HOME)/common/OCA;\
        $(SRC_HOME)/common/HostInterface;\
        $(SRC_HOME)/platform;\
        $(SRC_HOME)/platform/common;\
        $(SRC_HOME)/adamson;\
        $(USRINC)))
    else
    INCDIRS := $(subst ; ,;,$(subst \,/,.;\
        $(SRC_HOME)/inc;\
        $(SRC_HOME)/lib/inc;\
        $(SRC_HOME)/common;\
        $(SRC_HOME)/common/OCA;\
        $(SRC_HOME)/common/HostInterface;\
        $(SRC_HOME)/platform;\
        $(SRC_HOME)/platform/common;\
        $(SRC_HOME)/adamson))
    endif

    # Output directories
    OBJDIR := Obj
    OBJINT := intermediate
    OUTDIR := $(subst \,/,$(PRJ_HOME))/$(OBJDIR)/$(PLATFORM)/$(RELEASE)
    ifeq ($(GINTDIR),)
        GINTDIR := $(OUTDIR)/$(OBJINT)
    endif
    INTDIR := $(GINTDIR)/$(NAME)

    # Tools
    SD := CC -M -MP -march=native
    SE := sed
    RC :=
    ifeq ($(OS),Windows_NT)
        RM := erase /F
        MD := mkdir
        RN := ren _PATH__OLDNAME_ _NEWNAME_
        RD := rd /s/q
    else
        RM := rm -f
        MD := mkdir -p
        RN := mv _PATH__OLDNAME_ _PATH__NEWNAME_
        RD := rm -rf
    endif

    # Commands
    ifeq ($(OS),Windows_NT)
        IFEXIST    := if exist _FILE_ _COMMAND_
        IFNOTEXIST := if not exist _FILE_ _COMMAND_
    else
        IFEXIST    := if [ -e "_FILE_" ]; then _COMMAND_; fi
        IFNOTEXIST := if [ ! -e "_FILE_" ]; then _COMMAND_; fi
    endif

    # Other OS dependent variables
    # Work around to make sure only a single backslash is set
    ifeq ($(OS),Windows_NT)
        PATH_SEP := $(subst \\,\,\\)
    else
        PATH_SEP := $(subst \\,/,/)
    endif

    ifeq ($(PLATFORM),winntApp)

      CXXFLAGS :=
      RCFLAGS := -I "$(subst ;," -I ",$(INCDIRS))"


### linuxRelease ###############################################################

      ifeq ($(RELEASE),Release)

        # Tools
        # CC := gcc

        # Determine the extensions for the target platform
        OBJ_EXT := o
        DEP_EXT := dep
        EXE_EXT :=
        LIB_EXT := a
        DLL_EXT := so

        # Lists
        OBJS := $(patsubst %.cpp,%.$(OBJ_EXT),$(SRCS) $(LINUXSRCS))
        OBJS := $(patsubst %.c,%.$(OBJ_EXT),$(OBJS))
        DEPS := $(patsubst %.$(OBJ_EXT),%.$(DEP_EXT),$(OBJS))
        LIBS := $(LIBS) $(LINUXLIBS) $(EXTERNAL_LIBS)
        LIBS := $(addsuffix .$(LIB_EXT), $(LIBS))
        LIBS := $(addprefix $(OUTDIR)/, $(LIBS))

        SDFLAGS := -O2 -nostdlib -fno-strict-aliasing -ffunction-sections -fdata-sections -c -Wall -Wno-unknown-pragmas -x none \
                   -I"$(subst ;," -I",$(INCDIRS))" \
                   -D"NDEBUG" -DTARGET_LINUX -D"CPPUNIT_TUI_VERSION" -D"__STDC_FORMAT_MACROS" \
                   $(foreach USRDEF,$(USRDEFS),-D"$(USRDEF)") \
                   $(foreach USRUNDEF,$(USRUNDEFS),-U"$(USRUNDEF)")
        SDCFLAGS :=
        SDCPPFLAGS := -std=c++0x
        CCFLAGS = $(SDFLAGS) -fexceptions -fvisibility=hidden -march=armv8-a -mtune=cortex-a53 -o $(INTDIR)/$@
# That's for Linaro and the Snapdragon410 (Qualcomm APQ8016) processor; next is for Ubuntu 18.04.1
#       CCFLAGS = $(SDFLAGS) -fexceptions -fvisibility=hidden -m64 -mtune=generic -o $(INTDIR)/$@
        CXXFLAGS := -std=gnu++0x

        ifeq ($(TYPE),EXE)
          OUT_EXT := $(EXE_EXT)
          # LD := gcc
          LD := aarch64-poky-linux-ld
#         LDFLAGS = -Wl,--gc-sections -fno-keep-static-consts -fexceptions -march=armv8-a -maarch64linux -L$(OUTDIR) -o$@
# Use the above -Wl when using gcc. When using ld directly, it doesn't take -Wl. aarch64-poky-linux-ld doesn't have the -f options.
          LDFLAGS = --gc-sections -march=armv8-a -maarch64linux -L$(OUTDIR) -o$@
# That's for Linaro and the Snapdragon410 (Qualcomm APQ8016) processor; next is for Ubuntu 18.04.1
#         LDFLAGS = -Wl,--gc-sections -fno-keep-static-consts -fexceptions -m64 -mtune=x86-64 -L$(OUTDIR) -o$@
          LINUXSYSTEMLIBS := -lstdc++ -lrt -lpthread $(addprefix -l, $(LINUXSYSTEMLIBS))
        endif
        ifeq ($(TYPE),LIB)
          OUT_EXT := $(LIB_EXT)
          # LD := ar
          LDFLAGS = crus $@
        endif
        ifeq ($(TYPE),DLL)
          OUT_EXT := $(DLL_EXT)
          # LD := gcc
          LD := aarch64-poky-linux-ld
#         LDFLAGS = -Wl,--gc-sections -export-dynamic -fno-keep-static-consts -fexceptions -march=armv8-a -maarch64linux -L$(OUTDIR) -o$@
# Use the above -Wl when using gcc. When using ld directly, it doesn't take -Wl. aarch64-poky-linux-ld doesn't have the -f options.
          LDFLAGS = --gc-sections -export-dynamic -march=armv8-a -maarch64linux -L$(OUTDIR) -o$@
# That's for Linaro and the Snapdragon410 (Qualcomm APQ8016) processor; next is for Ubuntu 18.04.1
#         LDFLAGS = -Wl,--gc-sections -export-dynamic -fno-keep-static-consts -fexceptions -m64 -mtune=x86-64 -L$(OUTDIR) -o$@
          LINUXSYSTEMLIBS := -lstdc++ -lrt -lpthread $(addprefix -l, $(LINUXSYSTEMLIBS))
        endif
      endif

    endif #ifeq ($(PLATFORM),linuxApp)

  endif #ifneq ($(RELEASE),)
endif #ifneq ($(PLATFORM),)

################################################################################
# Phony target specification
################################################################################
.PHONY: goal all clean phonyclean $(NAME)\
        winntDebug winntRelease \
        winntDebug64 winntRelease64 \
        winntDebugClean winntReleaseClean \
        winntDebug64Clean winntRelease64Clean \
        linuxDebug linuxRelease \
        linuxDebugClean linuxReleaseClean

################################################################################
# Targets
################################################################################
goal: winntDebug winntRelease

all: winntDebug winntRelease \
     winntDebug64 winntRelease64

clean: winntDebugClean winntReleaseClean \
       winntDebug64Clean winntRelease64Clean

linuxRelease:
  ifneq (,$(findstring linux,$(TARGETS)))
    $(PREFIX)$(MAKE) -f $(NAME_MKE) $(NAME) --no-print-directory PLATFORM=linuxApp RELEASE=Release
  else
    $(PREFIX)echo $@ not configured for $(NAME)
  endif

linuxReleaseClean:
  ifneq (,$(findstring linux,$(TARGETS)))
    $(PREFIX)$(MAKE) -f $(NAME_MKE) phonyclean --no-print-directory PLATFORM=linuxApp RELEASE=Release CLEAN=Yes
  else
    $(PREFIX)echo linuxRelease not configured for $(NAME)
  endif

### Dependency files ###########################################################

$(INTDIR)/%.$(DEP_EXT) : %.c
    $(PREFIX)echo $(@F)
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$@),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$@),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$@.tmp),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$@.tmp),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(GINTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(GINTDIR)),$(IFNOTEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFNOTEXIST)))
  #
  # Do not use (OBJ_EXT) in the SED command, since all dependencies are generated with gcc.
  # Use .o instead
  #
    $(PREFIX)$(SD) $(SDCFLAGS) $(SDFLAGS) $< | $(SE) "s/$*.o:/$*.$(OBJ_EXT) $(subst /,\/,$@):/" > $(subst /,$(PATH_SEP),$@.tmp)
    $(PREFIX)$(subst _PATH_,$(subst /,$(PATH_SEP),$(INTDIR)/),$(subst _OLDNAME_,$(@F).tmp,$(subst _NEWNAME_,$(@F),$(RN))))

$(INTDIR)/%.$(DEP_EXT) : %.cpp
    $(PREFIX)echo $(@F)
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$@),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$@),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$@.tmp),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$@.tmp),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(GINTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(GINTDIR)),$(IFNOTEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFNOTEXIST)))
  #
  # Do not use (OBJ_EXT) in the SED command, since all dependencies are generated with gcc.
  # Use .o instead
  #
    $(PREFIX)$(SD) $(SDCPPFLAGS) $(SDFLAGS) $< | $(SE) "s/$*.o:/$*.$(OBJ_EXT) $(subst /,\/,$@):/" > $(subst /,$(PATH_SEP),$@.tmp)
    $(PREFIX)$(subst _PATH_,$(subst /,$(PATH_SEP),$(INTDIR)/),$(subst _OLDNAME_,$(@F).tmp,$(subst _NEWNAME_,$(@F),$(RN))))

### Object files ###############################################################

%.$(OBJ_EXT) : %.asm
    $(PREFIX)echo $(@F)
    $(PREFIX)$(AS) $(ASFLAGS) $<

%.$(OBJ_EXT) : %.S
    $(PREFIX)echo $(@F)
    $(PREFIX)$(AS) $(ASFLAGS) $<

%.$(RES_EXT) : %.rc
    $(PREFIX)echo $(@F)
    $(PREFIX)"$(RC)" $(RCFLAGS) -fo "$(INTDIR)/$(@F)" $<

%.$(OBJ_EXT) : %.c $(TOOL_DEPS)
  ifneq ($(CC),cl.exe)
    $(PREFIX)echo $(@F)
  endif
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)/$@),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$(INTDIR)/$@),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFNOTEXIST)))
    $(PREFIX)$(CC) $(CCFLAGS) $<

%.$(OBJ_EXT) : %.cpp $(TOOL_DEPS)
  ifneq ($(CC),cl.exe)
    $(PREFIX)echo $(@F)
  endif
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)/$@),$(subst _COMMAND_,$(RM) $(subst /,$(PATH_SEP),$(INTDIR)/$@),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFNOTEXIST)))
    $(PREFIX)$(CC) $(CCFLAGS) $(CXXFLAGS) $<

### Output file ################################################################

$(NAME): $(OUTFILE) $(BINFILE)

$(OUTFILE): $(INTDIR)/$(NAME).x $(OBJS) $(LIBS) $(NAME_MKE)
    $(PREFIX)echo $@
    $(PREFIX)$(subst _FILE_,$@,$(subst _COMMAND_,$(RM) $@,$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(OUTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(OUTDIR)),$(IFNOTEXIST)))
    ifneq (,$(findstring $(OBJINT),$(OBJS)))
        $(foreach obj,$(OBJS),$(shell echo $(obj) >> $(LSTFILE)))
    else
        $(foreach obj,$(OBJS),$(shell echo $(subst /,$(PATH_SEP),$(INTDIR)/$(obj)) >> $(LSTFILE)))
    endif
    ifneq (,$(filter $(PLATFORM),linuxApp))
      ifeq ($(TYPE),LIB)    
    $(PREFIX)ar $(LDFLAGS) @$(LSTFILE) $(LIBS) $(LINUXSYSTEMLIBS)
      else
        ifeq ($(TYPE),EXE)    
        $(PREFIX)aarch64-poky-linux-ld $(LDFLAGS) @$(LSTFILE) $(LIBS) $(LINUXSYSTEMLIBS)
        else
          ifeq ($(TYPE),DLL)    
        $(PREFIX)aarch64-poky-linux-ld $(LDFLAGS) @$(LSTFILE) $(LIBS) $(LINUXSYSTEMLIBS)
          else
        $(PREFIX)LD $(LDFLAGS) @$(LSTFILE) $(LIBS) $(LINUXSYSTEMLIBS)
          endif
        endif
      endif
    else
      ifeq ($(PLATFORM),winntApp)
        $(PREFIX)$(LD) $(LDFLAGS) @$(LSTFILE) $(WINNTSYSTEMLIBS)
      else
        $(PREFIX)$(LD) $(LDFLAGS) @$(LSTFILE)
      endif
    endif
    $(PREFIX)$(subst _FILE_,$(LSTFILE),$(subst _COMMAND_,$(RM) $(LSTFILE),$(IFEXIST)))

$(BINFILE): $(OUTFILE)
    $(PREFIX)echo $@
    $(PREFIX)$(B2B) $(B2BFLAGS) $(OUTFILE) $(BINFILE)

$(INTDIR)/$(NAME).x:
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(MD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFNOTEXIST)))
    $(PREFIX)echo Checkpoint file for component $(NAME) > $(subst /,$(PATH_SEP),$@)

### Clean ######################################################################

phonyclean:
  ifneq ($(PLATFORM),)
    ifneq ($(RELEASE),)
    $(PREFIX)$(subst _FILE_,$(subst /,$(PATH_SEP),$(INTDIR)),$(subst _COMMAND_,$(RD) $(subst /,$(PATH_SEP),$(INTDIR)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.pdb,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.pdb,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.map,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.map,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.dat,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.dat,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.exp,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.exp,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.lib,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.lib,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(patsubst %.$(OUT_EXT),%.err,$(OUTFILE)),$(subst _COMMAND_,$(RM) $(patsubst %.$(OUT_EXT),%.err,$(OUTFILE)),$(IFEXIST)))
    $(PREFIX)$(subst _FILE_,$(OUTFILE),$(subst _COMMAND_,$(RM) $(OUTFILE),$(IFEXIST)))
    else
    $(PREFIX)echo Target $@ should not be used from command line
    endif
  else
    $(PREFIX)echo Target $@ should not be used from command line
  endif

################################################################################
# Include dependency files
################################################################################
ifneq ($(PLATFORM),)
  ifneq ($(RELEASE),)
    #
    # If cleaning, we must not include dependency files.
    # Otherwise they will be created before cleaning.
    #
    ifeq ($(CLEAN),)
      ifeq (,$(findstring $(OBJINT),$(OBJS)))
        #
        # Use a - in front of the include, otherwise make will complain
        # when it is ran the first time (when there are no .dep files).
        #
        -include $(patsubst %.$(DEP_EXT),$(INTDIR)/%.$(DEP_EXT),$(DEPS))
      endif
    endif
  endif
endif

有人可以给我指出一个完整的Yocto层的简单示例,其中包括makefile和可以交叉编译的简单代码吗?我似乎很难找到,尤其是支持交叉编译的makefile.

Could someone point me at a simple example of a complete Yocto layer including makefile and simple code that cross-compiles? It seems difficult for me to find, especially the makefile that supports being used in cross-compilation.

一个重要的认识是文档在哪里涉及CFLAGS和LDFLAGS的路径变量和其他设置:Yocto大型手册中的所有变量均在第33章.变量表"中,

An important realization is where the documentation is about the path variables and other settings for the CFLAGS and LDFLAGS: with all variables in the Yocto mega-manual, in "Chapter 33. Variables Glossary", https://www.yoctoproject.org/docs/3.0/mega-manual/mega-manual.html#ref-variables-glos

推荐答案

Yocto依赖项概念

首先,您似乎在Yocto中混合了各种依赖项概念:

Yocto dependency concepts

First, you seem to mix various dependency concepts in Yocto:

  • IMAGE_INSTALL 是一个图像依赖性,告诉Yocto参数in的配方必须安装在最终图像中.应该将其放置在图像配方中,而不是包装配方中.我认为添加到软件包配方中不会告诉Yocto将此依赖项添加到配方的暂存目录中.
  • RDEPENDS 用于包配方中,并在运行时告诉Yocto配方取决于参数中的包.然后,如果安装了需要它们的软件包,它将在最终映像中安装所需的运行时依赖项.
    一个基本示例是一个包含脚本外壳的配方,该脚本在运行时依赖于某些外壳解释器.
  • DEPENDS 也用于包配方中,并告诉Yocto配方在编译时取决于参数中的包.它将在配方的暂存目录中添加头文件和库.
  • IMAGE_INSTALL is an image dependency telling to Yocto the recipe in parameter must be installed in the final image. It should be placed inside image recipe and not inside package recipe. I don't think adding that into a package recipe tells to Yocto to add this dependencies to the recipe's staging directory.
  • RDEPENDS is used inside package recipe and tells to Yocto the recipe depends on the packages in parameter at runtime. Then it will install in final image the required runtime dependencies if you install the package requiring them.
    A basic example is a recipe containing a script shell depends at runtime on some shell interpreter.
  • DEPENDS is used also inside package recipe and tells to Yocto the recipe depends on the packages in parameters at compile time. It will add the header files and the libraries in the staging directory of your recipe.

话虽这么说, libstdc ++ libpthread librt 是工具链的一部分,您无需在自己的程序中添加显式依赖项食谱.它们将被毫不费力地安装在登台目录或您的配方中.

That being said, libstdc++, libpthread and librt are part of the toolchain and you don't need to add explicit dependencies in your recipes for that. They will be installed in the staging directory or your recipe without any effort.

关于 libdns_sd ,经过我的快速研究,该库由mDNS提供.然后,您需要为其添加依赖项:

Regarding the libdns_sd, following my quick research, this library is provided by mDNS. You then need to add a dependency on it:

DEPENDS = "mdns"

如上所述,这会将头文件* .a和* .so添加到配方的暂存目录中.

As explained above, this will add the header files, *.a and *.so in the staging directory of your recipe.

一旦正确配置了依赖项,编译器就需要知道include和库目录在哪里,而在Makefile中显然缺少此目录,可能是因为您假设依赖项是宿主工具链的一部分.直接为主机构建时,编译器会知道在哪里可以找到包含(例如,在/usr/include中进行搜索)和库,这使得此过程非常简单.

Once the dependencies are correctly configured, your compiler needs to know where are the include and library directories and this is clearly missing in your Makefile probably because you assume the dependencies are part of the host toolchain. When you build directly for the host, the compiler knows where to find includes (search in /usr/include for example) and libraries which makes this process quite simple.

但是,对于标准的交叉编译项目,在Yocto中,标头和库位于其他位置,您需要在Makefile中正确指定它们.

However, as for a standard cross compilation project, in Yocto the headers and libraries are located elsewhere and you need to specify that correctly in your Makefile.

在Yocto中管理Makefile项目有多种可能性,但是在所有情况下,您都需要一个Makefile,该Makefile可以接收变量(CFLAGS,LDFLAGS等)或可选参数,以从配方中调用时传递给编译器/链接器.

There is multiple possibilities to manage a Makefile project in Yocto but in all cases, you need a Makefile which can receive variables (CFLAGS, LDFLAGS, etc) or optional arguments to pass to the compiler/linker when called from your recipe.

由于您没有提供Yocto食谱,因此我将举一个例子说明如何做和一些建议.另外,我专注于编译方面,该示例尚不完整,应该适合其他构建步骤(如安装).

Since you don't give the Yocto recipe, I will give an example on how it can be done and some suggestions. Also, I focus on compile aspect, the example is not complete and should probably be adapted for other build steps (like install).

DEPENDS += "my-extralib"

# Change eventually the default source directory
S = "${WORKDIR}/git"

EXTRA_OEMAKE = " 'CC=${CC}' \
    'CFLAGS=${CFLAGS} ${TARGET_CC_ARCH} -I${S}/inc -I${STAGING_DIR_TARGET}${includedir}/my-extralib-include' \
    'LDFLAGS=-lrt -lpthread -lm -lmy-extralib -L${STAGING_DIR_TARGET}${libdir}/my-extralib-libdir' \
    'BUILDDIR=${S}' \
    'OTHER_DEFINE=${OTHER_YOCTO_VAR}' \
"

使用EXTRA_OEMAKE,Yocto可以自动为您完成许多任务,例如配置,编译和安装.如果要覆盖它们,也可以这样做:

Using EXTRA_OEMAKE lets Yocto do a lot of tasks automatically for you like the configure, compile and install. If you want to override them, this is also possible:

do_compile() {
    # modify the Makefile on the fly as an example
    cp ${S}/Makefile.orig ${S}/Makefile
    sed -i -e 's:= $(LDFLAGS):?= $(LDFLAGS):' ${S}/Makefile
    oe_runmake SOME_OVERRIDE='some-override'
}

您还可以禁用诸如configure之类的步骤,该步骤可能在您的情况下不使用:

You can also disable a step like the configure which is probably not used in your case:

do_configure[noexec] = "1"

一些提示

  • 如果您从Yocto入手,有很多东西要学习,一开始很难找到如何管理所有可能性和选项的方法.我强烈建议您从一个简单的Makefile和最少的源文件开始,以专注于Yocto方面.
  • 您可以在网上找到很多食谱示例(还有Yocto,Poky基本食谱),它们可能与您想要达到的目标很接近.Yocto的文档确实很完整,但它更多地是基础参考.具体实现可以在现有食谱中找到.
  • 您的配方的build目录中的temp目录是一个金矿,其中包含不同构建步骤的所有脚本和日志.这是创建食谱时首先要查看的地方.
  • 这篇关于如何将librt和libpthread链接到Yocto中的新层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆