Shared Library (Dynamic linking) - It's not about libs

Vinicius Pereira - Jul 11 - - Dev Community

This is my first post here so, let's go.

Disclaimer: I won't create expectations with my posts. Everything I share is part of my learning process, which often involves explaining things to others. I found this method to be particularly effective during my time at 42 School. Therefore, I'll be posting about various topics I'm currently learning or have already learned.


Why this post?

I'm actually doing a challenge for a job vacancy and I was struggling with shared objects and I'm doing it in my home, so I remember who hard are don't have another person near you to ask things even if they don't know the answer, they help you to think and find new ways or they have new ideas or even better, they help you to have new ideas and so forth.


First step

This challenge involves creating a shared library in any programming language of my choice.
The library will be tested with a specifically crafted binary file written in C. My goal is to ensure the library functions as intended based on the provided test outputs.


Working on it

During a recent interview, I was presented with a challenge: create a shared library that functions as a CSV processor. Initially, I opted to develop it in Go. It seemed like a straightforward task...

While writing the Go code itself wasn't an issue, the real challenge arose in integrating the library with the C binary. Every attempt resulted in different errors, often related to missing symbols in the generated shared object (.so file).

Fortunately, I eventually found a solution and was able to test the library using the provided binary. However, running the program resulted in a core dump, indicating unexpected behavior.

To address this issue, I opted to switch to C++. The primary reason was the perceived ease of interfacing shared objects created in C++ with C binaries. This approach minimized debugging difficulties and eliminated core dumps.


Final Thoughts

Despite the initial hurdles, I'm still tackling the CSV processor challenge in C++. Having a better understanding of shared objects and dynamic linking (thanks to my previous experience with static libraries) is definitely helpful. However, the initial issues I encountered took a significant amount of time to resolve.

Cya!

Some references to learn about static and dynamic:

Reduce Your Compile Time
Low level learning video I love this channel
Introduction and creation
C Programming

. .
Terabox Video Player