Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BSEC Shared Library for Linux x64

    BSEC Shared Library for Linux x64


    We are developing an application that is responsible for collecting data from thousands of different remote sensors, including BME680 and BME688, using a .Net C# application running on Ubuntu 22.04 on Intel x64 hardware.

    We have created managed to create a prototype under Windows 10, where we managed to connect to multiple BME680 sensors and integrated BSEC multi-instance version using P/Invoke.

    The integration code looks like this:

    private const string BsecLibraryName = "BSECLibrary64.dll";
    [DllImport(BsecLibraryName, EntryPoint = "bsec_init_m", CallingConvention = CallingConvention.Cdecl)]    
    private static extern int bsec_init_m(IntPtr bsec_instance);
    [DllImport(BsecLibraryName, EntryPoint = "bsec_do_steps_m", CallingConvention = CallingConvention.Cdecl)]
    private static extern int bsec_do_steps_m(IntPtr bsec_instance,
                                            [In] BSEC_input_struct[] inputs,
                                            byte number_inputs,
                                            [Out] BSEC_output_struct[] outputs,
                                            [In, Out] ref byte number_outputs);
    // and so on ...

    However, we are facing an issue when porting the code from windows to linux. The problem is that for windows there is a dynamic library (.dll), while there is no shared library (.so) available for linux. All we can find for linux is BSEC2.4.0.0_Generic_Release_23012023/algo/normal_version/bin/gcc/Linux/m64/libalgobsec.a, which is a static library and for .Net P/Invoke to work it reqires the DllImport to point to a dynamic library (a.k.a .so in linux).

    We have tried to create an .so in multiple ways so far, but we are always facing different issues. For example:

    $ gcc -shared -o test.c bin/gcc/Linux/m64/libalgobsec.a
    /usr/bin/ld: bin/gcc/Linux/m64/libalgobsec.a(ChannelHub.o): warning: relocation against `uv' in read-only section `.text'
    /usr/bin/ld: bin/gcc/Linux/m64/libalgobsec.a(bsec_codegen_do_steps.o): relocation R_X86_64_PC32 against symbol `uv2' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: bad value
    collect2: error: ld returned 1 exit status

    We are uncertain if getting a libalgobsec.a compiled with -fPIC would be enough to create a shared object. 

    Can anyone help us obtain a working shared library of BSEC for linux ?


    P.S. the content of the test.c is not relevant at the moment and was just used to force the libalgobsec.a to be included in the shared library:

    #include "inc/bsec_interface.h"
    #include "inc/bsec_interface_multi.h"
    void test()


    8 REPLIES 8

    Community Moderator
    Community Moderator

    Hi olsen,

    After our internal discussion, currently we only support to release BSEC .a library, no plan to develop share library .so. Sorry for the inconvenience.

    Thank you for your response.

    In this case would it be possible to obtain the BSEC library for  Linux x64, build with gcc and -fPIC option?
    While I have seen there were a instances of such libraries being provided for BSEC 1.x in the forum, we specifically need the multi instance support that was added in 2.x.

    Do you think that would enable us to create a wrapper in C and integrate the library in our C# solution?

    Community Moderator
    Community Moderator

    Hi olsen,

    In this case would it be possible to obtain the BSEC library for Linux x64, build with gcc and -fPIC option?
    Reply: you can give us more information about how to setup the compier environment, then we can try to compile it and check whether it can compile successfully.

    Do you think that would enable us to create a wrapper in C and integrate the library in our C# solution?
    Reply: we can only provide BSEC C library, so we haven't do this test to support C#.

    Thanks @BSTRobin,

    We did a a few quick tests here with a dummy static library and we beleieve we only need -fPIC added to what ever you already have as compiler flags.

    Assuming you do the following:

    gcc -m64 -c file1.c -o file1.o
    gcc -m64 -c file1.c -o file2.o

    ar rcs libalgobsec.a file1.o file2.o ....

    If possible to do instead:
    gcc -m64 -fPIC -c file1.c -o file1.o

    Thank you for your support.