我有一个构建共享库(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)
谢谢!
答案 0 :(得分: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
,您将看到执行了哪些命令来编译插件。将其与用于手动编译的设置进行比较,您将看到成功构建和不成功构建之间的区别。