iOS Question My Journey Wrapping B4i Library

walterf25

Expert
Licensed User
Longtime User
Quick update for anyone who is interested, since this has been a wild experience for me, I have wrapped quiet a few B4i libraries before, most of them for personal and some of them for clients.

This specific library which I posted a question about on this other thread has had me chasing my own tail for about 2 weeks now, and I must say I was on the border of throwing myself in front of a train due to the stress 🤣 hopefully this helps anyone else who comes across this same issue.

Basically, I created the library wrapper in xcode, added the necessary frameworks, dependencies etc. This is the first time I wrapped a library that gets build with CocaPods, it was interesting learning a little about Pods, the library compiles just fine, I added it to the Libs folder in my local build host, also added the .a library file along with the header file, created the xml file from the header file and added it to my AdditionalLibs folder in my PC, up until this point everything is fine and dandy, however upon compiling and running the app, even though the app doesn't crash, I kept getting this error:

No registered object with name: mediapipe::tasks::vision::pose_landmarker::poseLandmarkerGraph; Unable to find Calculator "mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"

This had me working day and night for almost 2 weeks, I wish I had taken a step back and calm myself down and thought a little bit more about the error. Finally after taking a break I was able to see clear and think things through, I created an Xcode example where I integrated the library I was wrapping, ran the project on my iPhone device and it worked perfectly, no errors, so now the question was, what am I missing, what is the difference between the Xcode Project and my B4i project, Erel suggested I compare the contents of both IPA files from both projects, however that didn't really give me any more insight as to what the issue was.

Finally I started going through the Build Settings of each project in Xcode, the native Xcode project and the B4iProject opening it in Xcode, I started seeing all this different settings under Build Settings of the native xcode project, I asked ChatGPT, Gemini and a few other AI services, and all of them were hinting at possibly missing graph file, however I was 1000% sure that the said graph file was being included in the B4i project, as I could see the libMediaPipeTasksCommon_device_graph.a file inside the project, so how could this be.

Until I realized that there are some linker flags that are added to the native Xcode project when initializing the Pod and installing the MediaPipeTasksVision.framework and MediaPipeTasksCommon.framework, there seems to be some scripts that run when compiling that add those extra linker flags to the Build Settings Tab. The main linker flag I was missing was:

ObjC
-force_load
"$(PROJECT_DIR)/libMediaPipeTasksCommon_device_graph.a"

Apparently this linker flag is needed when working with libraries that are written in C++ and it forces the compiler to link all the symbols associated with the library.
Now I can compile and run the B4i project directly from Xcode and the library doesn't give me the error anymore, also I had to unlink the file from the Build Phase tab, otherwise I would get an error saying there were duplicate symbols.

Now my question is the following, given that I need to add those linker flags to the project, is there a way to add this linker flags through B4i, my guess is NO, as I haven't found anything relating to this in the forums, but was wondering given that this is a community full of very smart people, how can we figure this out, hopefully @Erel has some additional insight regarding this, but I really need to deliver this project to my client, I have tried setting that linker flags in the b4i library wrapper xcode project, but it seems that when the app gets compiled B4i clears those linker flags, hence the need to add them manually, the problem with this is that when I need to make changes to the library wrapper, or add more functions and I need to recompile then I need to set the linker flags manually again.

Any thought, suggestions and ideas are welcome, hopefully this helps someone else who comes across this issue.

Thank you all.
 

walterf25

Expert
Licensed User
Longtime User
Have you added the iCPP library in your B4i project?
I have not, can you explain why I would need this library and what is its purpose?
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Have you added the iCPP library in your B4i project?
Just added the iCPP library to the project, and I see that all it does is include the -lc++ flag, but that doesn't help, I actually need to add the -force_load $(PROJECT_DIR)/libMediaPipeTasksCommon_device_graph.a flags also, as this is the only way the library will load all the necessary symbols in order for it work, at the moment, I am adding those linker flags manually in the xcode project after compiling the through the B4i IDE, but this is taking way too long every time i need to add/change/modify anything in the library.

Really wish there was a way to add these linker flags and add steps in the Build Phases sections as well.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
The force load flag is added automatically in some conditions. It will be added if there it at least one swift framework.
Hi Erel, I have been getting around this issue by compiling the app through B4i, then opening the xcode B4iProject then running a ruby script which adds the linker flags then recompiling the app in xcode, this works even though it is a tedious and long process.

I am having a separate issue now where I introduced the iLottie library, and now I am getting a whole bunch of other errors, it seems the iLottie library consists if swift framework and the issue I am seeing now is that in fact the compiler is adding a lot of the -force_load flags which load a bunch of other libraries and I get errors saying duplicate symbols, the app will not compile in B4i now, any idea on how to get around this, I am so close to finalizing my app but I definitely need both iLottie and my wrapped library to work, I'm so close to finalizing this app yet so close to giving up :(

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
The problem is most probably not because of the force-load flag, however I'm not familiar with iLottie implementation so can't say much.
I think the problem is the force-load flag, because it is force-loading all dependencies including the ones that I already have included in my project, so it throws the error of duplicate symbols, once I take out all those force-load flags and leave only the -force_load libMediaPipeTasksCommon_device_graph.a then the project compiles without any issues.
 
Upvote 0
Top