Search code examples
cembeddedshared-librariesyocto.so

Yocto- gcc cannot find shared library


I have a layer which creates a shared library (libbbexample.so) 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 libbbexample.so.

File helloworld.c:

#incude<stdio.h>
#include<bbexample.h>

int main()
{
    int data;
    
    data = get_data(); // this function is present in libbbexample.so 
    
    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 libbbexample.so) to 7.

Thanks


Solution

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

    Change

    -libbbexample
    

    with

    -lbbexample
    

    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: