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);
}
... View more