1

I built my cython modules to so file on macOS and it works fine. Is it possible to build so file for linux specific on macOS as well?

My current solution is to run a python container with necessary modules installed. Then mount current folder to the working directory in container, execute the compilation inside container. It works fine so far, but I'm looking for a easier solution which is to compile linux specific so files directly on macOS.

Howard
  • 3,638
  • 4
  • 32
  • 39
  • 1
    Why not compile it in a script? – xilpex May 04 '20 at 16:51
  • I do build it with script right now within linux container, but it seems building .so file across platform relies on many factors of the OS (I'm not familiar with C++, correct me if I'm wrong). I'm looking for a solution to build .so file for linux platform on my macbook, so that it could be convenient for the further work. – Howard May 06 '20 at 12:15
  • The fundamental problem here is that you're trying to create something OS-specific, which inevitably requires significant chunks of the interface provided with the OS. Not having the whole thing available makes things difficult because you have to simulate, but also because you can't do things like actually testing your output. – Mad Physicist May 10 '20 at 18:32
  • What I'm saying is that using a VM is likely optimal in many ways. – Mad Physicist May 10 '20 at 18:33

2 Answers2

1

It seems that very few requirement like what I'm doing for this use case. Here post a solution what I'm doing right now and hope it could help some one who run into the same issue.

Generally, I run into a docker container with a volume mounted on my disk, the python code is placed there. Then I can compile my python files in container and I can also get my compiled .so files on my local file.

One command will do the trick.

docker run -it -v $(pwd):/dist python:3.8-buster bash -c "pip3 install Cython==0.29.17 && cythonize -3 -i [YOUR PYTHON CODE ROOT Folder]/*.py" 
Howard
  • 3,638
  • 4
  • 32
  • 39
1

What you're trying to do is 'cross-compiling'. This post tries to answer the question of the best way to do cross-compiling from Mac to Linux, with links to some (outdated) tools. In short - it's not easy, and I wouldn't go that way unless there's a really compelling reason to do so.

There are two tools that claim to make this process (somewhat?) easier:

But again, I'm not sure it's worth the effort.

Roy2012
  • 11,755
  • 2
  • 22
  • 35