0

I've written a short Python script, which I would like to be portable, in the sense that it could run on a variety of very stripped-down systems, on which it may not be possible to install Python.

At first, I turned to Cython. My plan was:

  1. Use Cython to compile my Python script into C.
  2. Use GCC to compile the C into bytecode.
  3. Run the bytecode anywhere.

Step (1) was easy. I ran cython my_script.py, and it dutifully spat out my_script.c. Step (2) is where I'm stuck at the moment. Running gcc my_script.c was more troublesome. Initially, I got compile errors of the form: header_file.h: No such file or directory. I could resolve these by copying and pasting the files in question from /usr/include/ into the same directory as my_script.c, but then I ran into the next problem, dozens of errors of the form: undefined reference to Something_or_Other. Does anyone know where I might be going wrong? I've already run sudo apt install python3-dev, and I've tried gcc my_script.c -I/user/include/, but neither seems to achieve anything.

I've also considered just writing my script in C. However, the thing that I'm trying to write involves both dictionaries and Unicode characters, both of which are a real headache in C.

  • I'm not convinced GCC can compile into "run anywhere" bytecode. Typically it produces files fairly tied to a specific CPU – DavidW Jan 22 '22 at 18:07
  • The undefined reference errors tell you that you need to link to a library (which is different from "including" it) – DavidW Jan 23 '22 at 10:32
  • @DavidW I would be grateful if you could elaborate on the distinction between the two. – chancellorofpaphos Jan 23 '22 at 11:25
  • https://stackoverflow.com/questions/7096152/c-difference-between-linking-library-and-adding-include-directories looks reasonably comprehensive. Essentially the `#include "some_header.h" tells C that some functions exist; the linking step provides the implementation. – DavidW Jan 23 '22 at 11:31

0 Answers0