Yocto / Poky: install and use shared library .so on separate layers





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm trying to learn how to build custom linux images with Yocto and I'm struggling to create an image with both a shared library and a program that uses it.



I started by following this tutorial and everything went ok. Then I tried to separate the program from the library in two different layers, without success.



I started with the library code:



greetings.c



#include <stdio.h>
#include <string.h>
#include "greetings.h"
void get_greeting(char * buffer) {

if(buffer == NULL) {
return;
}

char greeting = "Hello world from the greetings libn";
strcpy(buffer, greeting);
return;
}


greetings.h



void get_greeting(char * buffer);


Makefile.am



AUTOMAKE_OPTIONS = foreign

lib_LTLIBRARIES = libgreetings.la
libgreetings_la_SOURCES = greetings.c

include_HEADERS = greetings.h
libgreetings_la_CFLAGS = -Wall -Werror -fPIC
libgreetings_la_LDFLAGS = -shared
ACLOCAL_AMFLAGS = -I m4


configure.ac



AC_INIT([Greetings lib], 1.0)
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_CONFIG_MACRO_DIR([m4])
LT_INIT()
AC_CONFIG_FILES(Makefile)
AC_OUTPUT


I added this code to a git repository and created a "meta-greetings" layer with the layer.conf and recipe files:



layer.conf



# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-greetings"
BBFILE_PATTERN_meta-greetings = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-greetings = "6"

LAYERDEPENDS_meta-greetings = "core"
LAYERSERIES_COMPAT_meta-greetings = "thud"
IMAGE_INSTALL_append = " greetings"


recipes-greetings/greetings/greetings_0.1.bb



SUMMARY = "bitbake-layers recipe"
DESCRIPTION = "Simple helloworld lib"
DEPENDS = ""
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

KBRANCH = "master"
SRCREV = "1a908a8f8616af704ce71d693e88c6d4498f24c4"

SRC_URI = "git://bitbucket.org/Grifo/greetings_lib.git;branch=${KBRANCH};protocol=ssh"

S = "${WORKDIR}/git"

inherit autotools


So far so good, I added this layer to my bblayers file and proceeded to compile the final image. I run it in qemu and even got to see the files in /usr/lib:



enter image description here



However, there's no "libgreetings.so". I don't know if that may be the cause of the problem (still to explain) but the previously mentioned tutorial got similar results so I proceeded.



After that I did the program:



helloworld.c



#include <stdio.h>
#include "greetings.h"
int main(void) {
char greeting[40];
get_greeting(greeting);
printf("Hello world!n");
printf("%s", greeting);
return 0;
}


Makefile.am



AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = hello_world
hello_world_SOURCES = helloworld.c
hello_world_LDADD = $(libdir)/libgreetings.so
ACLOCAL_AMFLAGS = -I m4


configure.ac



AC_INIT([Hello world], 1.0)
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES(Makefile)
AC_OUTPUT


Added this code to git and created a "meta-helloworld" layer with the files:



layer.conf



# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-helloworld"
BBFILE_PATTERN_meta-helloworld = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-helloworld = "7"

LAYERDEPENDS_meta-helloworld = "core meta-greetings"
LAYERSERIES_COMPAT_meta-helloworld = "thud"
IMAGE_INSTALL_append = " helloworld"


recipes-helloworld/helloworld/helloworld_0.1.bb



SUMMARY = "bitbake-layers helloworld"
DESCRIPTION = "Simple helloworld program"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

KBRANCH = "master"
SRCREV = "6a29425473286028e85e74003f2f57ecaf766354"

SRC_URI = "git://bitbucket.org/Grifo/hello_world.git;branch=${KBRANCH};protocol=ssh"

DEPENDS = "greetings"

S = "${WORKDIR}/git"

inherit autotools


After all this I bitbaked the final image again but got the following error:



(...)
Sstate summary: Wanted 7 Found 0 Missed 7 Current 737 (0% match, 99% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: helloworld-0.1-r0 do_compile: oe_runmake failed
ERROR: helloworld-0.1-r0 do_compile: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
ERROR: Logfile of failure stored in: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040
Log data follows:
| DEBUG: SITE files ['endian-little', 'bit-32', 'arm-common', 'arm-32', 'common-linux', 'common-glibc', 'arm-linux', 'arm-linux-gnueabi', 'common']
| DEBUG: Executing shell function do_compile
| NOTE: make -j 8
| make: *** No rule to make target `/usr/lib/libgreetings.so', needed by `hello_world'. Stop.
| ERROR: oe_runmake failed
| WARNING: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/run.do_compile.12040:1 exit 1 from 'exit 1'
| ERROR: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
ERROR: Task (/var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 1966 tasks of which 1965 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
/var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile
Summary: There was 1 WARNING message shown.
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.


I am sorry for the really long question but I felt like I need to give all the details since I don't know if the problem comes from my recipe or my autotools files.



Before I built the recipes and compile it using yocto, I first compiled and run it in my host computer using the shell and everything run fine. I compiled and make install the greetings library (/usr/local/lib) and after that compiled the helloworld program which run without any problem.



I know that I could probably do this easily all within the same layer, however I'm trying to do it in separate layers to simulate different projects. Another requirement of mine is to use autotools instead of cmake.



Thank you in advance,



Grifo



EDIT:



I got it to work! Thank you Alexander Kanavin for pointing me in the right direction. I just had to change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings in my helloworld's Makefile.am.










share|improve this question































    1















    I'm trying to learn how to build custom linux images with Yocto and I'm struggling to create an image with both a shared library and a program that uses it.



    I started by following this tutorial and everything went ok. Then I tried to separate the program from the library in two different layers, without success.



    I started with the library code:



    greetings.c



    #include <stdio.h>
    #include <string.h>
    #include "greetings.h"
    void get_greeting(char * buffer) {

    if(buffer == NULL) {
    return;
    }

    char greeting = "Hello world from the greetings libn";
    strcpy(buffer, greeting);
    return;
    }


    greetings.h



    void get_greeting(char * buffer);


    Makefile.am



    AUTOMAKE_OPTIONS = foreign

    lib_LTLIBRARIES = libgreetings.la
    libgreetings_la_SOURCES = greetings.c

    include_HEADERS = greetings.h
    libgreetings_la_CFLAGS = -Wall -Werror -fPIC
    libgreetings_la_LDFLAGS = -shared
    ACLOCAL_AMFLAGS = -I m4


    configure.ac



    AC_INIT([Greetings lib], 1.0)
    AM_INIT_AUTOMAKE
    AC_PROG_CC
    AC_CONFIG_MACRO_DIR([m4])
    LT_INIT()
    AC_CONFIG_FILES(Makefile)
    AC_OUTPUT


    I added this code to a git repository and created a "meta-greetings" layer with the layer.conf and recipe files:



    layer.conf



    # We have a conf and classes directory, add to BBPATH
    BBPATH .= ":${LAYERDIR}"

    # We have recipes-* directories, add to BBFILES
    BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
    ${LAYERDIR}/recipes-*/*/*.bbappend"

    BBFILE_COLLECTIONS += "meta-greetings"
    BBFILE_PATTERN_meta-greetings = "^${LAYERDIR}/"
    BBFILE_PRIORITY_meta-greetings = "6"

    LAYERDEPENDS_meta-greetings = "core"
    LAYERSERIES_COMPAT_meta-greetings = "thud"
    IMAGE_INSTALL_append = " greetings"


    recipes-greetings/greetings/greetings_0.1.bb



    SUMMARY = "bitbake-layers recipe"
    DESCRIPTION = "Simple helloworld lib"
    DEPENDS = ""
    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

    KBRANCH = "master"
    SRCREV = "1a908a8f8616af704ce71d693e88c6d4498f24c4"

    SRC_URI = "git://bitbucket.org/Grifo/greetings_lib.git;branch=${KBRANCH};protocol=ssh"

    S = "${WORKDIR}/git"

    inherit autotools


    So far so good, I added this layer to my bblayers file and proceeded to compile the final image. I run it in qemu and even got to see the files in /usr/lib:



    enter image description here



    However, there's no "libgreetings.so". I don't know if that may be the cause of the problem (still to explain) but the previously mentioned tutorial got similar results so I proceeded.



    After that I did the program:



    helloworld.c



    #include <stdio.h>
    #include "greetings.h"
    int main(void) {
    char greeting[40];
    get_greeting(greeting);
    printf("Hello world!n");
    printf("%s", greeting);
    return 0;
    }


    Makefile.am



    AUTOMAKE_OPTIONS = foreign

    bin_PROGRAMS = hello_world
    hello_world_SOURCES = helloworld.c
    hello_world_LDADD = $(libdir)/libgreetings.so
    ACLOCAL_AMFLAGS = -I m4


    configure.ac



    AC_INIT([Hello world], 1.0)
    AM_INIT_AUTOMAKE
    AC_PROG_CC
    AC_CONFIG_MACRO_DIR([m4])
    AC_CONFIG_FILES(Makefile)
    AC_OUTPUT


    Added this code to git and created a "meta-helloworld" layer with the files:



    layer.conf



    # We have a conf and classes directory, add to BBPATH
    BBPATH .= ":${LAYERDIR}"

    # We have recipes-* directories, add to BBFILES
    BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
    ${LAYERDIR}/recipes-*/*/*.bbappend"

    BBFILE_COLLECTIONS += "meta-helloworld"
    BBFILE_PATTERN_meta-helloworld = "^${LAYERDIR}/"
    BBFILE_PRIORITY_meta-helloworld = "7"

    LAYERDEPENDS_meta-helloworld = "core meta-greetings"
    LAYERSERIES_COMPAT_meta-helloworld = "thud"
    IMAGE_INSTALL_append = " helloworld"


    recipes-helloworld/helloworld/helloworld_0.1.bb



    SUMMARY = "bitbake-layers helloworld"
    DESCRIPTION = "Simple helloworld program"

    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

    KBRANCH = "master"
    SRCREV = "6a29425473286028e85e74003f2f57ecaf766354"

    SRC_URI = "git://bitbucket.org/Grifo/hello_world.git;branch=${KBRANCH};protocol=ssh"

    DEPENDS = "greetings"

    S = "${WORKDIR}/git"

    inherit autotools


    After all this I bitbaked the final image again but got the following error:



    (...)
    Sstate summary: Wanted 7 Found 0 Missed 7 Current 737 (0% match, 99% complete)
    NOTE: Executing SetScene Tasks
    NOTE: Executing RunQueue Tasks
    ERROR: helloworld-0.1-r0 do_compile: oe_runmake failed
    ERROR: helloworld-0.1-r0 do_compile: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
    ERROR: Logfile of failure stored in: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040
    Log data follows:
    | DEBUG: SITE files ['endian-little', 'bit-32', 'arm-common', 'arm-32', 'common-linux', 'common-glibc', 'arm-linux', 'arm-linux-gnueabi', 'common']
    | DEBUG: Executing shell function do_compile
    | NOTE: make -j 8
    | make: *** No rule to make target `/usr/lib/libgreetings.so', needed by `hello_world'. Stop.
    | ERROR: oe_runmake failed
    | WARNING: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/run.do_compile.12040:1 exit 1 from 'exit 1'
    | ERROR: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
    ERROR: Task (/var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile) failed with exit code '1'
    NOTE: Tasks Summary: Attempted 1966 tasks of which 1965 didn't need to be rerun and 1 failed.

    Summary: 1 task failed:
    /var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile
    Summary: There was 1 WARNING message shown.
    Summary: There were 2 ERROR messages shown, returning a non-zero exit code.


    I am sorry for the really long question but I felt like I need to give all the details since I don't know if the problem comes from my recipe or my autotools files.



    Before I built the recipes and compile it using yocto, I first compiled and run it in my host computer using the shell and everything run fine. I compiled and make install the greetings library (/usr/local/lib) and after that compiled the helloworld program which run without any problem.



    I know that I could probably do this easily all within the same layer, however I'm trying to do it in separate layers to simulate different projects. Another requirement of mine is to use autotools instead of cmake.



    Thank you in advance,



    Grifo



    EDIT:



    I got it to work! Thank you Alexander Kanavin for pointing me in the right direction. I just had to change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings in my helloworld's Makefile.am.










    share|improve this question



























      1












      1








      1








      I'm trying to learn how to build custom linux images with Yocto and I'm struggling to create an image with both a shared library and a program that uses it.



      I started by following this tutorial and everything went ok. Then I tried to separate the program from the library in two different layers, without success.



      I started with the library code:



      greetings.c



      #include <stdio.h>
      #include <string.h>
      #include "greetings.h"
      void get_greeting(char * buffer) {

      if(buffer == NULL) {
      return;
      }

      char greeting = "Hello world from the greetings libn";
      strcpy(buffer, greeting);
      return;
      }


      greetings.h



      void get_greeting(char * buffer);


      Makefile.am



      AUTOMAKE_OPTIONS = foreign

      lib_LTLIBRARIES = libgreetings.la
      libgreetings_la_SOURCES = greetings.c

      include_HEADERS = greetings.h
      libgreetings_la_CFLAGS = -Wall -Werror -fPIC
      libgreetings_la_LDFLAGS = -shared
      ACLOCAL_AMFLAGS = -I m4


      configure.ac



      AC_INIT([Greetings lib], 1.0)
      AM_INIT_AUTOMAKE
      AC_PROG_CC
      AC_CONFIG_MACRO_DIR([m4])
      LT_INIT()
      AC_CONFIG_FILES(Makefile)
      AC_OUTPUT


      I added this code to a git repository and created a "meta-greetings" layer with the layer.conf and recipe files:



      layer.conf



      # We have a conf and classes directory, add to BBPATH
      BBPATH .= ":${LAYERDIR}"

      # We have recipes-* directories, add to BBFILES
      BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
      ${LAYERDIR}/recipes-*/*/*.bbappend"

      BBFILE_COLLECTIONS += "meta-greetings"
      BBFILE_PATTERN_meta-greetings = "^${LAYERDIR}/"
      BBFILE_PRIORITY_meta-greetings = "6"

      LAYERDEPENDS_meta-greetings = "core"
      LAYERSERIES_COMPAT_meta-greetings = "thud"
      IMAGE_INSTALL_append = " greetings"


      recipes-greetings/greetings/greetings_0.1.bb



      SUMMARY = "bitbake-layers recipe"
      DESCRIPTION = "Simple helloworld lib"
      DEPENDS = ""
      LICENSE = "MIT"
      LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

      KBRANCH = "master"
      SRCREV = "1a908a8f8616af704ce71d693e88c6d4498f24c4"

      SRC_URI = "git://bitbucket.org/Grifo/greetings_lib.git;branch=${KBRANCH};protocol=ssh"

      S = "${WORKDIR}/git"

      inherit autotools


      So far so good, I added this layer to my bblayers file and proceeded to compile the final image. I run it in qemu and even got to see the files in /usr/lib:



      enter image description here



      However, there's no "libgreetings.so". I don't know if that may be the cause of the problem (still to explain) but the previously mentioned tutorial got similar results so I proceeded.



      After that I did the program:



      helloworld.c



      #include <stdio.h>
      #include "greetings.h"
      int main(void) {
      char greeting[40];
      get_greeting(greeting);
      printf("Hello world!n");
      printf("%s", greeting);
      return 0;
      }


      Makefile.am



      AUTOMAKE_OPTIONS = foreign

      bin_PROGRAMS = hello_world
      hello_world_SOURCES = helloworld.c
      hello_world_LDADD = $(libdir)/libgreetings.so
      ACLOCAL_AMFLAGS = -I m4


      configure.ac



      AC_INIT([Hello world], 1.0)
      AM_INIT_AUTOMAKE
      AC_PROG_CC
      AC_CONFIG_MACRO_DIR([m4])
      AC_CONFIG_FILES(Makefile)
      AC_OUTPUT


      Added this code to git and created a "meta-helloworld" layer with the files:



      layer.conf



      # We have a conf and classes directory, add to BBPATH
      BBPATH .= ":${LAYERDIR}"

      # We have recipes-* directories, add to BBFILES
      BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
      ${LAYERDIR}/recipes-*/*/*.bbappend"

      BBFILE_COLLECTIONS += "meta-helloworld"
      BBFILE_PATTERN_meta-helloworld = "^${LAYERDIR}/"
      BBFILE_PRIORITY_meta-helloworld = "7"

      LAYERDEPENDS_meta-helloworld = "core meta-greetings"
      LAYERSERIES_COMPAT_meta-helloworld = "thud"
      IMAGE_INSTALL_append = " helloworld"


      recipes-helloworld/helloworld/helloworld_0.1.bb



      SUMMARY = "bitbake-layers helloworld"
      DESCRIPTION = "Simple helloworld program"

      LICENSE = "MIT"
      LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

      KBRANCH = "master"
      SRCREV = "6a29425473286028e85e74003f2f57ecaf766354"

      SRC_URI = "git://bitbucket.org/Grifo/hello_world.git;branch=${KBRANCH};protocol=ssh"

      DEPENDS = "greetings"

      S = "${WORKDIR}/git"

      inherit autotools


      After all this I bitbaked the final image again but got the following error:



      (...)
      Sstate summary: Wanted 7 Found 0 Missed 7 Current 737 (0% match, 99% complete)
      NOTE: Executing SetScene Tasks
      NOTE: Executing RunQueue Tasks
      ERROR: helloworld-0.1-r0 do_compile: oe_runmake failed
      ERROR: helloworld-0.1-r0 do_compile: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
      ERROR: Logfile of failure stored in: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040
      Log data follows:
      | DEBUG: SITE files ['endian-little', 'bit-32', 'arm-common', 'arm-32', 'common-linux', 'common-glibc', 'arm-linux', 'arm-linux-gnueabi', 'common']
      | DEBUG: Executing shell function do_compile
      | NOTE: make -j 8
      | make: *** No rule to make target `/usr/lib/libgreetings.so', needed by `hello_world'. Stop.
      | ERROR: oe_runmake failed
      | WARNING: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/run.do_compile.12040:1 exit 1 from 'exit 1'
      | ERROR: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
      ERROR: Task (/var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile) failed with exit code '1'
      NOTE: Tasks Summary: Attempted 1966 tasks of which 1965 didn't need to be rerun and 1 failed.

      Summary: 1 task failed:
      /var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile
      Summary: There was 1 WARNING message shown.
      Summary: There were 2 ERROR messages shown, returning a non-zero exit code.


      I am sorry for the really long question but I felt like I need to give all the details since I don't know if the problem comes from my recipe or my autotools files.



      Before I built the recipes and compile it using yocto, I first compiled and run it in my host computer using the shell and everything run fine. I compiled and make install the greetings library (/usr/local/lib) and after that compiled the helloworld program which run without any problem.



      I know that I could probably do this easily all within the same layer, however I'm trying to do it in separate layers to simulate different projects. Another requirement of mine is to use autotools instead of cmake.



      Thank you in advance,



      Grifo



      EDIT:



      I got it to work! Thank you Alexander Kanavin for pointing me in the right direction. I just had to change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings in my helloworld's Makefile.am.










      share|improve this question
















      I'm trying to learn how to build custom linux images with Yocto and I'm struggling to create an image with both a shared library and a program that uses it.



      I started by following this tutorial and everything went ok. Then I tried to separate the program from the library in two different layers, without success.



      I started with the library code:



      greetings.c



      #include <stdio.h>
      #include <string.h>
      #include "greetings.h"
      void get_greeting(char * buffer) {

      if(buffer == NULL) {
      return;
      }

      char greeting = "Hello world from the greetings libn";
      strcpy(buffer, greeting);
      return;
      }


      greetings.h



      void get_greeting(char * buffer);


      Makefile.am



      AUTOMAKE_OPTIONS = foreign

      lib_LTLIBRARIES = libgreetings.la
      libgreetings_la_SOURCES = greetings.c

      include_HEADERS = greetings.h
      libgreetings_la_CFLAGS = -Wall -Werror -fPIC
      libgreetings_la_LDFLAGS = -shared
      ACLOCAL_AMFLAGS = -I m4


      configure.ac



      AC_INIT([Greetings lib], 1.0)
      AM_INIT_AUTOMAKE
      AC_PROG_CC
      AC_CONFIG_MACRO_DIR([m4])
      LT_INIT()
      AC_CONFIG_FILES(Makefile)
      AC_OUTPUT


      I added this code to a git repository and created a "meta-greetings" layer with the layer.conf and recipe files:



      layer.conf



      # We have a conf and classes directory, add to BBPATH
      BBPATH .= ":${LAYERDIR}"

      # We have recipes-* directories, add to BBFILES
      BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
      ${LAYERDIR}/recipes-*/*/*.bbappend"

      BBFILE_COLLECTIONS += "meta-greetings"
      BBFILE_PATTERN_meta-greetings = "^${LAYERDIR}/"
      BBFILE_PRIORITY_meta-greetings = "6"

      LAYERDEPENDS_meta-greetings = "core"
      LAYERSERIES_COMPAT_meta-greetings = "thud"
      IMAGE_INSTALL_append = " greetings"


      recipes-greetings/greetings/greetings_0.1.bb



      SUMMARY = "bitbake-layers recipe"
      DESCRIPTION = "Simple helloworld lib"
      DEPENDS = ""
      LICENSE = "MIT"
      LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

      KBRANCH = "master"
      SRCREV = "1a908a8f8616af704ce71d693e88c6d4498f24c4"

      SRC_URI = "git://bitbucket.org/Grifo/greetings_lib.git;branch=${KBRANCH};protocol=ssh"

      S = "${WORKDIR}/git"

      inherit autotools


      So far so good, I added this layer to my bblayers file and proceeded to compile the final image. I run it in qemu and even got to see the files in /usr/lib:



      enter image description here



      However, there's no "libgreetings.so". I don't know if that may be the cause of the problem (still to explain) but the previously mentioned tutorial got similar results so I proceeded.



      After that I did the program:



      helloworld.c



      #include <stdio.h>
      #include "greetings.h"
      int main(void) {
      char greeting[40];
      get_greeting(greeting);
      printf("Hello world!n");
      printf("%s", greeting);
      return 0;
      }


      Makefile.am



      AUTOMAKE_OPTIONS = foreign

      bin_PROGRAMS = hello_world
      hello_world_SOURCES = helloworld.c
      hello_world_LDADD = $(libdir)/libgreetings.so
      ACLOCAL_AMFLAGS = -I m4


      configure.ac



      AC_INIT([Hello world], 1.0)
      AM_INIT_AUTOMAKE
      AC_PROG_CC
      AC_CONFIG_MACRO_DIR([m4])
      AC_CONFIG_FILES(Makefile)
      AC_OUTPUT


      Added this code to git and created a "meta-helloworld" layer with the files:



      layer.conf



      # We have a conf and classes directory, add to BBPATH
      BBPATH .= ":${LAYERDIR}"

      # We have recipes-* directories, add to BBFILES
      BBFILES += "${LAYERDIR}/recipes-*/*/*.bb
      ${LAYERDIR}/recipes-*/*/*.bbappend"

      BBFILE_COLLECTIONS += "meta-helloworld"
      BBFILE_PATTERN_meta-helloworld = "^${LAYERDIR}/"
      BBFILE_PRIORITY_meta-helloworld = "7"

      LAYERDEPENDS_meta-helloworld = "core meta-greetings"
      LAYERSERIES_COMPAT_meta-helloworld = "thud"
      IMAGE_INSTALL_append = " helloworld"


      recipes-helloworld/helloworld/helloworld_0.1.bb



      SUMMARY = "bitbake-layers helloworld"
      DESCRIPTION = "Simple helloworld program"

      LICENSE = "MIT"
      LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8"

      KBRANCH = "master"
      SRCREV = "6a29425473286028e85e74003f2f57ecaf766354"

      SRC_URI = "git://bitbucket.org/Grifo/hello_world.git;branch=${KBRANCH};protocol=ssh"

      DEPENDS = "greetings"

      S = "${WORKDIR}/git"

      inherit autotools


      After all this I bitbaked the final image again but got the following error:



      (...)
      Sstate summary: Wanted 7 Found 0 Missed 7 Current 737 (0% match, 99% complete)
      NOTE: Executing SetScene Tasks
      NOTE: Executing RunQueue Tasks
      ERROR: helloworld-0.1-r0 do_compile: oe_runmake failed
      ERROR: helloworld-0.1-r0 do_compile: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
      ERROR: Logfile of failure stored in: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040
      Log data follows:
      | DEBUG: SITE files ['endian-little', 'bit-32', 'arm-common', 'arm-32', 'common-linux', 'common-glibc', 'arm-linux', 'arm-linux-gnueabi', 'common']
      | DEBUG: Executing shell function do_compile
      | NOTE: make -j 8
      | make: *** No rule to make target `/usr/lib/libgreetings.so', needed by `hello_world'. Stop.
      | ERROR: oe_runmake failed
      | WARNING: /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/run.do_compile.12040:1 exit 1 from 'exit 1'
      | ERROR: Function failed: do_compile (log file is located at /var/tmp/workspaces/grifo/poky/build/tmp/work/armv5e-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_compile.12040)
      ERROR: Task (/var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile) failed with exit code '1'
      NOTE: Tasks Summary: Attempted 1966 tasks of which 1965 didn't need to be rerun and 1 failed.

      Summary: 1 task failed:
      /var/tmp/workspaces/grifo/poky/meta-helloworld/recipes-helloworld/helloworld/helloworld_0.1.bb:do_compile
      Summary: There was 1 WARNING message shown.
      Summary: There were 2 ERROR messages shown, returning a non-zero exit code.


      I am sorry for the really long question but I felt like I need to give all the details since I don't know if the problem comes from my recipe or my autotools files.



      Before I built the recipes and compile it using yocto, I first compiled and run it in my host computer using the shell and everything run fine. I compiled and make install the greetings library (/usr/local/lib) and after that compiled the helloworld program which run without any problem.



      I know that I could probably do this easily all within the same layer, however I'm trying to do it in separate layers to simulate different projects. Another requirement of mine is to use autotools instead of cmake.



      Thank you in advance,



      Grifo



      EDIT:



      I got it to work! Thank you Alexander Kanavin for pointing me in the right direction. I just had to change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings in my helloworld's Makefile.am.







      c makefile yocto autotools






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 8 at 10:14







      Grifo

















      asked Jan 3 at 16:49









      GrifoGrifo

      469




      469
























          1 Answer
          1






          active

          oldest

          votes


















          3














          libgreetings.so is a file needed only for development and so it does not get installed to the image (unless you also install libgreetings-dev package - that's where it went).



          During cross-compile, you typically specify libraries to link with like this:
          -lgreetings



          So change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings.



          I would start with that. Typically you shouldn't hardcode them like that in the makefile, but rather 'discover' and check the library in configure.ac (e.g. using pkg-config, assuming your library installs the corresponding .pc file), and set the appropriate compiler and linker flags:



          PKG_CHECK_MODULES(GREETINGS, [greetings])



          Then, in Makefile.am:



          hello_world_LDADD = $(GREETINGS_LIBS)






          share|improve this answer


























          • Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

            – Grifo
            Jan 4 at 12:54











          • Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

            – Grifo
            Jan 4 at 13:23











          • I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

            – Grifo
            Jan 4 at 15:26











          • Not sure what should I edit specifically?

            – Alexander Kanavin
            Jan 6 at 13:31






          • 1





            @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

            – John Bollinger
            Jan 7 at 11:56












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026504%2fyocto-poky-install-and-use-shared-library-so-on-separate-layers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          libgreetings.so is a file needed only for development and so it does not get installed to the image (unless you also install libgreetings-dev package - that's where it went).



          During cross-compile, you typically specify libraries to link with like this:
          -lgreetings



          So change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings.



          I would start with that. Typically you shouldn't hardcode them like that in the makefile, but rather 'discover' and check the library in configure.ac (e.g. using pkg-config, assuming your library installs the corresponding .pc file), and set the appropriate compiler and linker flags:



          PKG_CHECK_MODULES(GREETINGS, [greetings])



          Then, in Makefile.am:



          hello_world_LDADD = $(GREETINGS_LIBS)






          share|improve this answer


























          • Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

            – Grifo
            Jan 4 at 12:54











          • Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

            – Grifo
            Jan 4 at 13:23











          • I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

            – Grifo
            Jan 4 at 15:26











          • Not sure what should I edit specifically?

            – Alexander Kanavin
            Jan 6 at 13:31






          • 1





            @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

            – John Bollinger
            Jan 7 at 11:56
















          3














          libgreetings.so is a file needed only for development and so it does not get installed to the image (unless you also install libgreetings-dev package - that's where it went).



          During cross-compile, you typically specify libraries to link with like this:
          -lgreetings



          So change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings.



          I would start with that. Typically you shouldn't hardcode them like that in the makefile, but rather 'discover' and check the library in configure.ac (e.g. using pkg-config, assuming your library installs the corresponding .pc file), and set the appropriate compiler and linker flags:



          PKG_CHECK_MODULES(GREETINGS, [greetings])



          Then, in Makefile.am:



          hello_world_LDADD = $(GREETINGS_LIBS)






          share|improve this answer


























          • Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

            – Grifo
            Jan 4 at 12:54











          • Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

            – Grifo
            Jan 4 at 13:23











          • I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

            – Grifo
            Jan 4 at 15:26











          • Not sure what should I edit specifically?

            – Alexander Kanavin
            Jan 6 at 13:31






          • 1





            @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

            – John Bollinger
            Jan 7 at 11:56














          3












          3








          3







          libgreetings.so is a file needed only for development and so it does not get installed to the image (unless you also install libgreetings-dev package - that's where it went).



          During cross-compile, you typically specify libraries to link with like this:
          -lgreetings



          So change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings.



          I would start with that. Typically you shouldn't hardcode them like that in the makefile, but rather 'discover' and check the library in configure.ac (e.g. using pkg-config, assuming your library installs the corresponding .pc file), and set the appropriate compiler and linker flags:



          PKG_CHECK_MODULES(GREETINGS, [greetings])



          Then, in Makefile.am:



          hello_world_LDADD = $(GREETINGS_LIBS)






          share|improve this answer















          libgreetings.so is a file needed only for development and so it does not get installed to the image (unless you also install libgreetings-dev package - that's where it went).



          During cross-compile, you typically specify libraries to link with like this:
          -lgreetings



          So change hello_world_LDADD = $(libdir)/libgreetings.so to hello_world_LDADD = -lgreetings.



          I would start with that. Typically you shouldn't hardcode them like that in the makefile, but rather 'discover' and check the library in configure.ac (e.g. using pkg-config, assuming your library installs the corresponding .pc file), and set the appropriate compiler and linker flags:



          PKG_CHECK_MODULES(GREETINGS, [greetings])



          Then, in Makefile.am:



          hello_world_LDADD = $(GREETINGS_LIBS)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 7 at 14:08









          Grifo

          469




          469










          answered Jan 4 at 9:06









          Alexander KanavinAlexander Kanavin

          2356




          2356













          • Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

            – Grifo
            Jan 4 at 12:54











          • Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

            – Grifo
            Jan 4 at 13:23











          • I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

            – Grifo
            Jan 4 at 15:26











          • Not sure what should I edit specifically?

            – Alexander Kanavin
            Jan 6 at 13:31






          • 1





            @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

            – John Bollinger
            Jan 7 at 11:56



















          • Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

            – Grifo
            Jan 4 at 12:54











          • Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

            – Grifo
            Jan 4 at 13:23











          • I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

            – Grifo
            Jan 4 at 15:26











          • Not sure what should I edit specifically?

            – Alexander Kanavin
            Jan 6 at 13:31






          • 1





            @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

            – John Bollinger
            Jan 7 at 11:56

















          Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

          – Grifo
          Jan 4 at 12:54





          Thank you for your answer! So, how do I know if my library is installing the correspondent .pc file? I assume it isn't since I added nothing for that effect, right?

          – Grifo
          Jan 4 at 12:54













          Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

          – Grifo
          Jan 4 at 13:23





          Also, should I add "hello_world_LDFLAGS = -lgreetings" to my Makefile.am? Meaning I''l have both that and "hello_world_LDADD = $(GREETINGS_LIBS)". Or should I just use one of them?

          – Grifo
          Jan 4 at 13:23













          I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

          – Grifo
          Jan 4 at 15:26





          I got it to work. I just had to change "hello_world_LDADD = $(libdir)/libgreetings.so" to "hello_world_LDFLAGS = -lgreetings" and after that change my recipe's last line to "inherit autotools pkgconfig". Thank you for pointing me in the right direction, if you edit your post I'll mark it as the approved answer.

          – Grifo
          Jan 4 at 15:26













          Not sure what should I edit specifically?

          – Alexander Kanavin
          Jan 6 at 13:31





          Not sure what should I edit specifically?

          – Alexander Kanavin
          Jan 6 at 13:31




          1




          1





          @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

          – John Bollinger
          Jan 7 at 11:56





          @Gifro, although what you did may have worked, no, do not specify libraries in *_LDFLAGS, specify them in *_LDADD. This is about where the library options appear on the linbk command line, which matters. But do use the -lgreetings form, not the full library name and path. If you still have link errors at that point then check the order of the libraries with *LDADD.

          – John Bollinger
          Jan 7 at 11:56




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026504%2fyocto-poky-install-and-use-shared-library-so-on-separate-layers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          ts Property 'filter' does not exist on type '{}'

          mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window