Yocto + Autotools library + CMake application = linker error

NOTE: This question was originally posted at StackOverflow, and reproduced here by guidance of Toradex support.


I have a Yocto BSP with my own layer that includes an autotools 3rdy part library (libcoap).
My application “.bb” file has the following lines, telling libcoap is needed:

DEPENDS += "libcoap"
RDEPENDDS_${PN} += " libcoap libcoap-dev libcoap-devstatic"

I can see the library files are being copied to sysroot:

$ ls -l /projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/recipe-sysroot/usr/lib/libcoap*
-rw-r--r-- 2 udev udev 286430 Ago 21 13:53 /projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/recipe-sysroot/usr/lib/libcoap.a
lrwxrwxrwx 1 udev udev    173 Ago 29 14:33 /projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/recipe-sysroot/usr/lib/libcoap.so -> ../../projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/libcoap/4.1.2+gitAUTOINC+d48ab449fd-r0/image/usr/lib/libcoap.so.4.1.2
-rwxr-xr-x 2 udev udev  38444 Ago 21 13:53 /projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/recipe-sysroot/usr/lib/libcoap.so.4.1.2

It is not hard to noticed that the symlink is kind of weird:

/projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/recipe-sysroot/usr/lib/libcoap.so -> ../../projects/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/libcoap/4.1.2+gitAUTOINC+d48ab449fd-r0/image/usr/lib/libcoap.so.4.1.2

My libcoap.bb contains inherit relative_symlinks (otherwise an absolute link to “/projects” is created and bitbake fails) but the symlink created simply prepends “…/…/” to the original link.

So… the questions are:

  1. Why do I need inherit relative_symlinks? Shouldn’t make install create a symlink relative to sysroot out of the box?

Generated Makefile contains:

librootdir = $(DESTDIR)$(prefix)/lib
# ...
ln -s $(librootdir)/$(LIBSO).4.1.2 $(librootdir)/$(LIBSO)

And I thought $(DESTDIR) would already point to the correct place during bitbake’s installation…

  1. What is the right way to fix it? Could it be something wrong at the other side (the application trying to link against libcoap)?

Thanks in advance.


Resources

libcoap.bb is based on Internet and quite simple:

SUMMARY = "A C implementation of IETF Constrained Application Protocol (RFC 7252)"
DESCRIPTION = "Libcoap provides an implementation of the IETF CoAP protocol"
HOMEPAGE = "http://sourceforge.net/projects/libcoap/"
SECTION = "libs/network"

PROVIDES = "libcoap"

SRCREV = "d48ab449fd05801e574e4966023589ed7dac500b"
# Lookout for PV bump too when SRCREV is changed
PV = "4.1.2+git${SRCPV}"
LICENSE = "GPLv2 | BSD"
LIC_FILES_CHKSUM = "file://${S}/LICENSE.BSD;md5=1164f52f9c4db2c13f681b201010d518 \
                    file://${S}/LICENSE.GPL;md5=4641e94ec96f98fabc56ff9cc48be14b"

S = "${WORKDIR}/git"

SRC_URI = "git://git.code.sf.net/p/libcoap/code"

inherit autotools-brokensep relative_symlinks

EXTRA_OECONF += "--with-shared"
EXTRA_OEMAKE += "all"

INSANE_SKIP_${PN} = "ldflags"
BBCLASSEXTEND = "native nativesdk"

Additionally

I have tried to fix symlink in a do_install_append() in “libcoap.bb”:

do_install_append() {
	if [ -l ${D}/${libdir}/libcoap.so ]; then
		rm -f ${D}/${libdir}/libcoap.so
	fi

	cd ${D}/${libdir}
	ln -l libcoap.so.${LIBCOAP_VERSION} libcoap.so
}

But it gives me, when trying to build my application:

ERROR: coap-playground-1.0-r0 do_package_qa: QA Issue: /usr/bin/server contained in package coap-playground requires libcoap.so, but no providers found in RDEPENDS_coap-playground? [file-rdeps]
ERROR: coap-playground-1.0-r0 do_package_qa: QA run found fatal errors. Please consider fixing them.
ERROR: coap-playground-1.0-r0 do_package_qa: Function failed: do_package_qa
ERROR: Logfile of failure stored in: /home/udev/projects/nbiot/vf50/oe-core/build/tmp-glibc/work/armv7at2hf-neon-angstrom-linux-gnueabi/coap-playground/1.0-r0/temp/log.do_package_qa.12739
ERROR: Task (/home/udev/projects/nbiot/vf50/oe-core/build/../layers/meta-nbiot/recipes-playground/coap/coap-playground.bb:do_package_qa) failed with exit code '1'

hi @J4x

Welcome to the Toradex Community!!!

Could you provide the version of the hardware and the software of your module?
Which git branch did you compile?
Which commands did you use to build your application?

Hello @jaski.tx. Thank you for your interest.

Could you provide the version of the hardware and the software of your module?

Sorry but this is completely irrelevant since I didn’t even succeed to compile my application. Hardware versions were already informed on question input, but here it is again: Module is Colibri VF50 (V1.2A). Carrier board is Iris (V1.1B).

Which git branch did you compile?
I strictly followed instructions from Toradex Developer and repository is synchronized. I am not being very successful extracting information out of repo but I assure you I have not touched the defaults. The only changes I made are in:

  • "build/conf/local.conf, where I informed MACHINE ?= "colibri-vf" and IMAGE_INSTALL_append = " my-daemon".
  • “build/conf/bblayers.conf” where informed the existence of my own layer.
  • My own layer files, of course, and it consists basically of an external library whose “.bb” is based on this source and the simplest C++ application linking to it.

The exact contents of my “libcoap.bb” are reproduced at the bottom.

Which commands did you use to build your application?

bitbake libcoap    # Success here.
bitbake my-app    # Failure reported previously.

libcoap.bb

SUMMARY = "A C implementation of IETF Constrained Application Protocol (RFC 7252)"
DESCRIPTION = "Libcoap provides an implementation of the IETF CoAP protocol"
HOMEPAGE = "http://sourceforge.net/projects/libcoap/"
SECTION = "libs/network"

PROVIDES = "coap libcoap libcoap.so"

SRCREV = "d48ab449fd05801e574e4966023589ed7dac500b"

LIBCOAP_VERSION = "4.1.2"
# Lookout for PV bump too when SRCREV is changed
PV = "${LIBCOAP_VERSION}+git${SRCPV}"
LICENSE = "GPLv2 | BSD"
LIC_FILES_CHKSUM = "file://${S}/LICENSE.BSD;md5=1164f52f9c4db2c13f681b201010d518 \
                    file://${S}/LICENSE.GPL;md5=4641e94ec96f98fabc56ff9cc48be14b"

S = "${WORKDIR}/git"

SRC_URI = "git://git.code.sf.net/p/libcoap/code \
"
inherit autotools-brokensep
# inherit autotools-brokensep relative_symlinks

EXTRA_OECONF += "--with-shared"
EXTRA_OEMAKE += "all"

do_install_append() {
	[ -L ${D}/${libdir}/libcoap.so ] && rm -f ${D}/${libdir}/libcoap.so

	cd ${D}/${libdir}
	ln -s libcoap.so.${LIBCOAP_VERSION} libcoap.so
}

INSANE_SKIP_${PN} = "ldflags"
BBCLASSEXTEND = "native nativesdk"

NOTE

There is one fix to my-app.bb since the original post (DEPENDS and RDEPENDS were swapped):

DEPENDS_${PN} += " libcoap libcoap-dev libcoap-staticdev"
RDEPENDS_${PN} += " libcoap"

Please tell me if you need further details on “my-app”.

Thank you very much.

Thanks for this Information. We will work on this Issue and come soon back to you.

@jaski.tx the issue was solved in person with the customer.

Short description of the changes that were made:

In the user app, the syntax is DEPENDS = "libcoap" instead of DEPENDS_${PN} += " libcoap".

In libcoap.bb, I changed SRC_URI to use the develop branch of the current repository (GitHub - obgm/libcoap: A CoAP (RFC 7252) implementation in C).
It was necessary to inherit autotools-brokensep pkgconfig.

When building libcoap, autogen will throw an error about gnu-configize. This is because the autoreconf in OpenEmbedded is patched to use gnu-configize whereas the original source does not use it. So it’s necessary to add

EXTRA_AUTORECONF_append = " --exclude=gnu-configize"

This is libcoap_git.bb:

SUMMARY = "A CoAP (RFC 7252) implementation in C"
HOMEPAGE = "https://github.com/obgm/libcoap"

LICENSE = "GPL-2.0 | BSD-2-Clause"
LIC_FILES_CHKSUM = "file://COPYING;md5=faed8f005d476edd3f250599a4bb9a75 \
					file://LICENSE;md5=392fc94551666d2548e7642c07b2289d"

PV= "4.1.2+git${SRCPV}"
SRCREV = "b7772e8dd5a6b4ce0d3a636f75e6c7b7fbe67523"
SRC_URI = "git://github.com/obgm/libcoap.git;protocol=https;branch=develop \
"
DEPENDS = "libtool"
inherit autotools-brokensep pkgconfig

# OE's autoreconf is patched to use gnu-configize, which doesn't work for this recipe. Excluding it from the command.
EXTRA_AUTORECONF_append = " --exclude=gnu-configize"

EXTRA_OECONF += "--disable-documentation --disable-dtls --enable-shared"

S = "${WORKDIR}/git"

BBCLASSEXTEND = "native"

And this is an example of a recipe for an application using libcoap:

DESCRIPTION = "CoAP testbench project"
LICENSE = "MIT"
LIC_FILES = "file://LICENSE"

inherit cmake gettext

DEPENDS += "libcoap"

RDEPENDS_${PN} += " libcoap libcoap-dev libcoap-devstatic"

SRC_URI += " \
	file://simplest-demo/server.cpp	\
	file://simplest-demo/client.cpp	\
	file://simplest-demo/CMakeLists.txt	\
	file://CMakeLists.txt	\
	"

S = "${WORKDIR}"
PR="r0"

BBCLASSEXTEND = "native nativesdk"

@gustavo.tx: Perfect, that it worked. Thanks for the Information.