【问题标题】:Yocto: BUILD_LDFLAGS set to build system libraries, not targetYocto:BUILD_LDFLAGS 设置为构建系统库,而不是目标
【发布时间】:2018-06-14 22:24:48
【问题描述】:

我有一个构建共享库(一个 alsa 插件)的 makefile 配方。如果我在外面建立图书馆,如果 yocto 一切正常并且 alsa 将链接到图书馆。

但是,如果我使用 yocto 构建它,即使日志没有错误,当我尝试运行 alsa 时,我也会收到错误“无法打开共享库”。该库安装在错误消息引用的位置,并且它的权限是正确的。

从配方中,如果我打印出 BUILD_LDFLAGS 设置的内容,我注意到它指向 x86_64-linux(构建系统)库而不是“MACHINE”库(例如:-L//.build-yocto/ tmp/sysroots/x86_64-linux/lib"

我的问题是:

BUILD_LDFLAGS 是我问题的根源吗?

如果是这样,我该如何补救?

如果不是 BUILD_LDFLAGS,知道是什么问题。

这是我的食谱 bb 文件的副本:

SUMMARY = "..."
LICENSE = "CLOSED"

#Package release number 
PR = "r0"


###################################################################
#The following lines tell yocto where to get the source code from
#  This section is for git.  Comment out ALL this section if
#  you DO NOT want to pull from a git repo (local or remote).
#  If pulling from git uncomment and modify paths.
###################################################################
#Uncomment following line to pull from REMOTE git repo
#SRC_URI = "git://gitpath;protocol=ssh;branch=master"

#Uncomment following line and modify path to pull from LOCAL git repo clone
##SRC_URI = "git:///localgitpath;protocol=file;branch=master"

#Change hash to match the commit you want yocto to use
##SRCREV="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
##S = "${WORKDIR}/git/"

#  End of git section


###################################################################
#The following lines tell yocto where to use a local file system
# for the source.  Uncomment all lines and modify paths
###################################################################
SRC_URI = ""
inherit externalsrc
EXTERNALSRC = "/home/<my_path>"
EXTERNALSRC_BUILD = "/home/<my_path>"

#  End of local file system section

##################################################################
#END of where to get source code
##################################################################




#Ignore vendor ldflags checking and use ours
INSANE_SKIP_${PN} = "ldflags"

#Don't strip debug symbols
INHIBIT_PACKAGE_STRIP = "1" 
INHIBIT_SYSROOT_STRIP = "1" 

SOLIBS = ".so"

#Tell yocto that the .so files are real and not sym-links.
FILES_SOLIBSDEV = ""


#/usr/lib/alsa-lib
FILES_${PN} += "${libdir}/alsa-lib" 
#/usr/<PATH>
FILES_${PN} += "${prefix}/<PATH>" 

DEPENDS += "alsa-lib"

EXTRA_OEMAKE += "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include' 'BUILDDIR=${S}' 'DESTDIR=${D}'"

TARGET_CFLAGS += "-DPIC -fPIC -Wall -Wextra -O2 -g -I./include -I<path> -I-I<path2> -I<path3> -lasound"
TARGET_LDFLAGS += "-shared -lasound"

do_configure() {
   oe_runmake -f Makefile.yocto clean
}

do_compile() {
#   unset LDFLAGS TARGET_LDFLAGS BUILD_LDFLAGS
   echo "                                   Werkdir ${WORKDIR}"
   echo "                                   Compiler ${CC}"
   echo "                                   BUILD_LDFLAGS ${BUILD_LDFLAGS}"
   echo "                                   LDFLAGS ${LDFLAGS}"
   echo "                                   TARGET_LDFLAGS ${TARGET_LDFLAGS}"
  oe_runmake -f Makefile.yocto all 'CC=${CC}'
}



do_install() {
   install -d ${D}${libdir}
   install -d ${D}${libdir}/alsa-lib
   install -d ${D}${bindir}
   install -d ${D}${prefix}
   install -d ${D}${prefix}/<PATH>
   install -m 0644 <path_n>lib1.so ${D}${libdir}
   install -m 0644 <path_n>lib2.so.so ${D}${libdir}
   install -m 0644 <path_n>lib3.so.so ${D}${libdir}
   install -m 0644 <path_n>lib4.so.so ${D}${libdir}
   install -m 0644 <path_n>lib1pcm_plugin.so ${D}${libdir}/alsa-lib
   install -m 0755 <path_n>app1 ${D}${bindir}
   install -m 0755 <path_n>app2 ${D}${bindir}
   install -m 0755 <path_n>app3 ${D}${bindir}
   install -m 0755 <path_n>app4 ${D}${bindir}
   install -m 0755 <path_n>app5 ${D}${bindir}
   install -m 0755 <path_n>app6 ${D}${bindir}
   install -m 0755 <path_n>app7 ${D}${bindir}
   install -m 0755 <path_n>app8 ${D}${bindir}

}

生成文件:

# Makefile template for shared library

#Yocto will pass in the CC flag so this is commented out.  Otherwise the correct compiler won't be used
#CC = gcc # C compiler

#These are here to allow a build outside of Yocto (testing the build).  Yocto's CFLAGS
#and LDFLAGS will override these.
CFLAGS += -fPIC -Wall -Wextra -O2 -g -I<path1> -I<path2> -I<path2> # C flags
LDFLAGS = -shared  # linking flags

RM = rm -f  # rm command
TARGET_LIB = libasoundplugin.so # target lib


LIB1=lib1
PATH1=<path1>
LIB2=lib2
PATH2=<path2>

INCLUDE_FLAGS = -L$(PATH1) -l$(LIB1I) \
                -L$(PATH2) -l$(LIB2) \
                -lasound

SRCS = source.c


OBJS = $(SRCS:.c=.o)

.PHONY: all
all: ${TARGET_LIB}

$(TARGET_LIB): $(OBJS)
        $(CC) ${LDFLAGS} ${INCLUDE_FLAGS} -o $@ $^

$(SRCS:.c=.d):%.d:%.c
        $(CC) $(CFLAGS) -MM $< >$@

include $(SRCS:.c=.d)

.PHONY: clean
clean:
    -${RM} ${TARGET_LIB} ${OBJS} $(SRCS:.c=.d)

谢谢!

【问题讨论】:

    标签: yocto bitbake


    【解决方案1】:

    BUILD_LDFLAGS 是我问题的根源吗?

    没有。 BUILD_LDFLAGS 用于构建本机包,同时构建目标包。在您的情况下,TARGET_LDFLAGS 变量将用作LDFLAGS source

    这是我的食谱 bb 文件的副本

    它来自哪里?你是用模板写的吗? 正如我所见,alsa plugins 有一个配方,也许你可以将你的插件添加到这个配方中? 您也可以以a2jmidid 的配方为例,据我所知,它与您尝试做的很接近。除了设置依赖项、获取源、添加某些 ld 标志以及将生成的文件传递给包之外,它没有什么特别之处。

    关于 Makefile(我想这也是你的食谱):

    首先,yocto 不需要单独的 Makefile。

    #Yocto will pass in the CC flag so this is commented out.  Otherwise the correct compiler won't be used
    #CC = gcc # C compiler
    

    您正在从您的 .bb 配方中传递 CC(甚至两次:通过 EXTRA_OEMAKE 和在 do_compile 中)。无需注释掉 CC 变量,因为 Makefile have lower priority 中的定义与作为命令行参数传递的定义相比。

    为什么需要INCLUDE_FLAGS 变量?我不明白它做了什么(除了第三次向 gcc 传递一些标志)。

    最后,你可以去工作目录,打开文件temp/log.do_compile,你会看到执行了哪些命令来编译你的插件。将其与您用于手动编译的设置进行比较,您将看到成功和不成功构建之间的区别。

    【讨论】:

    • 感谢您的评论。我正在删除冗余并将日志与命令行输出进行比较。当我知道更多时会更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多