0

With the Makefile and hello.bb listed below I am able to compile and run my C project on target device. The issue I am facing is that libraries sqlite3 libmicrohttpd json-c are not included to rootfs of the image and I'm getting errors like that:

admin@orange-pi-r1:~# /var/hello.bin
Error loading shared library libmicrohttpd.so.12: No such file or directory (needed by /var/hello.bin)
Error loading shared library libjson-c.so.5: No such file or directory (needed by /var/hello.bin)
Error relocating /var/hello.bin: json_object_new_string: symbol not found
Error relocating /var/hello.bin: MHD_destroy_response: symbol not found
Error relocating /var/hello.bin: json_object_object_add: symbol not found
Error relocating /var/hello.bin: MHD_create_response_from_buffer: symbol not found
Error relocating /var/hello.bin: MHD_queue_response: symbol not found
Error relocating /var/hello.bin: MHD_start_daemon: symbol not found
Error relocating /var/hello.bin: json_object_new_array: symbol not found
Error relocating /var/hello.bin: MHD_add_response_header: symbol not found
Error relocating /var/hello.bin: json_object_put: symbol not found
Error relocating /var/hello.bin: json_object_to_json_string: symbol not found
Error relocating /var/hello.bin: MHD_stop_daemon: symbol not found
Error relocating /var/hello.bin: json_object_new_object: symbol not found
Error relocating /var/hello.bin: json_object_array_add: symbol not found
Error relocating /var/hello.bin: json_object_new_int: symbol not found

Why is that and how to fix it?

hello.bb recipe

SUMMARY = "hello"
LICENSE = "CLOSED"

SRCBRANCH = "hello"
SRCREV = "03b9c21ef46973d2a285db785a04620ebaf25db2"

SRC_URI = "git://git@bitbucket.org/hello/hello.git;branch=${SRCBRANCH};protocol=ssh"

S = "${WORKDIR}/git"

DEPENDS = "sqlite3 libmicrohttpd json-c"

INSANE_SKIP:${PN} += "ldflags"

do_compile() {
    cd ${S}/src && oe_runmake
}

do_install() {
    install -d ${D}/var/
    install -m 0644 ${S}/src/hello.bin ${D}/var/hello.bin
}

FILES:${PN} = "/var/hello.bin"

Makefile

CC ?= gcc

CFLAGS += -O2
CFLAGS += -I./include
CFLAGS += -I${STAGING_INCDIR}/usr/lib

LDLIBS += -lmicrohttpd -lsqlite3 -ljson-c
LDFLAGS += -L${STAGING_LIBDIR}/usr/lib

cc-headers = \
    hello.h \
    hello_db.h \
    hello_http.h \
    hello_list.h

cc-targets = \
    hello.o \
    hello_db.o \
    hello_http.o

%.o: %.c $(cc-headers)
    $(CC) -c -o $@ $< $(CFLAGS)

all: $(cc-targets)
    $(CC) -o helo.bin $(CFLAGS) $(LDLIBS) $(cc-targets)

clean:
    rm *.o
  • Are you saying that the libraries are available at build time but not at run time? Then you should install them on your runtime system. If you don't want to or can't do that, then you'll have to link the libraries statically. – MadScientist Jan 04 '23 at 16:51
  • @MadScientist Yes exactly that. I thought build system got that covered for me. I was wrong I guess. – BlameCapitalism Jan 04 '23 at 18:18
  • @MadScientist trying to install missing libraries manually caused this `WARNING: hello-1.0-r0 do_package: libmicrohttpd-0.9.75 was registered as shlib provider for libmicrohttpd.so.12, changing it to hello-dev-1.0 because it was built later` – BlameCapitalism Jan 04 '23 at 18:42
  • I don't know anything about yocto etc. so I can't help with that. When you link a program, the linker will always look for a shared library to link first by default. Only if that shared library doesn't exist, will it fall back to a static library. If you want to force the link to use static libraries you have to add `-static` option to the link line. Note that this means you have to have a static library installed (sometimes they're in different packages than the shared library) and it's possible you need other options as well. – MadScientist Jan 04 '23 at 18:56

1 Answers1

1

DEPENDS specifies build time dependencies.

You need to add libmicrohttpd and json-c to RDEPENDS (Runtime dependencies):

RDEPENDS_${PN} += "libmicrohttpd json-c"
Talel BELHADJSALEM
  • 3,199
  • 1
  • 10
  • 30
  • [this](https://stackoverflow.com/a/53596975/10337382) suggests otherwise. And I had tried it earlier, it does not help. – BlameCapitalism Jan 04 '23 at 16:25
  • You need to check the libmicrohttpd recipe and see if it has separate package for the libraries – Talel BELHADJSALEM Jan 04 '23 at 16:46
  • This recipe (libmicrohttpd) ships dynamic libraries itself. Running `oe-pkgdata-util list-pkg-files -p libmicrohttpd` shows `libmicrohttpd: /usr/lib/libmicrohttpd.so.12` – BlameCapitalism Jan 04 '23 at 18:20
  • Well well well, how did the turntables. You were right all along. I cannot understand why it did not work first 2 times clean-building, but I guess 3rd time is the charm. Thanks! – BlameCapitalism Jan 10 '23 at 16:34