how to build a .so lib on MacOS

Can I build a .so lib on MacOS? I have a project using openCV and have built a .dylib on my MacOS, and now I need to deploy my project on docker(Linux) and I hope I can build a .so on my MacOS and directly use it in Linux. Is there any way?

There is a way but you’re entering the cross-compilation land where you have to set up a proper cross-compilation toolchain on your Mac and then tell CMake to use it (via a toolchain file).

Thanks. This helped me a lot