Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BSEC Shared Library for Linux x64

    BSEC Shared Library for Linux x64

    olsen
    Member

    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 2.4.0.0 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 BSECLibrary64.so 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()
    {
        bsec_init();
        bsec_init_m(NULL);
    }

     

    8 REPLIES 8

    BSTRobin
    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 2.4.0.0 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?

    BSTRobin
    Community Moderator
    Community Moderator

    Hi olsen,

    In this case would it be possible to obtain the BSEC 2.4.0.0 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.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist