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

    Hello @BSTRobin ,

    Is there any progress? Will you be able to build libalgobsec.a with -fPIC?


    Community Moderator
    Community Moderator

    Hi olsen,

    Sorry for the delay reply.

    After our internal discussion, current BSEC release package didn't contain the libalgobsec.a with -fPIC under ubuntu system you requested.
    If you design a project with BME68x and request the library, could you provide your email address? Then we will contact with you.

    Hi BSTRobin,

    I do have the same problem too. I was trying to compile the libalgobsec.a into my library as shared library but failed. I had privately message you. Looking forward for your fast response. Thanks.

    I would also like package with compiled with -fPIC. would that be possible? we would like to update to the latest version.