Preparing a C++ .so (which has it's own dependency; another C++ .so), to be used within Xamarin app

Viewed 36

Background information

I am working as an intern on an Android app for an aerospace company, & they want me to build an app which grabs data from sensors they purchased, & display it real-time on a mobile app wirelessly (over wifi). The manufacturer of the sensors supplied us with their driver files to use to make my own program (they refused to provide original .cpp versions of the libraries)

Manufacturer Driver Files:

  • card.h
  • libcard.so
  • utils.h
  • libutils.so

I've successfully built a barebones, terminal-only desktop version of my app using said drivers, linking the .so files manually using g++ on WSL2. I'd now like to use the C++ library I created on top of the drivers to power the mobile version, which will eventually be cross-platform, but for now my main focus is Xamarin.Android.

My Library (requires all Manufacture Driver Files):

  • main.cpp (Only used for testing wfb.* library)
  • wfb.h
  • wfb.cpp (Will be converted to .so for use in Xamarin app)

Main issue

I know how to use a c++ shared library within the Xamarin.Android app if there is only 1 layer of dependencies, but I am totally lost about how to handle my dependency (my library) having its own dependency (driver files). I think I need card.h, libcard.so, utils.h, libutils.so, & wfb.cpp to be compiled into wfb.so such that I can include wfb.so & wfb.h within the Xamarin lib directory so I can call the functions I created in wfb.cpp from C#, but I cannot get that to work. I'd imagine it's because I am going about this the wrong way.

Disclaimer:

I am 100% new to libraries and mobile apps, so if what I am asking here is ridiculous, or there is a better/easier work-around, please do let me know.

1 Answers

Well C++ solves its dependencies using linker. So during compile time (while creating object files) you need only headers than linker comes up and resolve linking to another libraries while building executable but during shared library creation it will be only compiled and linker is used later by you C# app. So if your wfb.so has another dependencies (libutils.so) you have to load them also by your C# application than if wfb.so will need to call some function from libutils.so application know symbol where to jump. If dependend lib is not loaded it should fail with some segmentation error or something similar.

With regards to header file. Makefile of your shared library just needs to use -I flag to point directory where header file is located.

Related