Search code examples

Yocto- gcc cannot find shared library

I have a layer which creates a shared library ( in usr/lib directory in a distribution build by Yocto. The library contains several functions.

So I have created a new layer in which I have written a program which will use functions provided by

File helloworld.c:


int main()
    int data;
    data = get_data(); // this function is present in 
    printf("data is %d",data);
    return 0;

So I have tried bitbake the new layer, but I am getting the error "cannot find -libbbexample".

The contents of .bb files of new layer are as follows

do_compile() {
    ${CC} helloworld.c -o helloworld -libbbexample ${LDFLAGS} 

do_install() {
    install -d ${D}${bindir}
    install -m 0755 helloworld ${D}${bindir}

I have set the following priority for layers:

  • priority of old layer (which will create the shared library) to 6;
  • priority of new layer (which will make use shared library to 7.



  • To add lib to your gcc command you have to trim the lib from the name.





    The man as reference.

    If this is not enough you have to grand that .so file is compiled and installed before the helloworld example. You can use: