2

I want my cython program to be standalone executable on linux, not to be imported. After

cython --embed

i got a c file,now how can i make it executable?

user1779646
  • 809
  • 1
  • 8
  • 21
  • what are you trying to do? are you trying to make it `import`able in Python or are you trying to embed python and execute it? Please edit your question and elaborate on these to make it a bit easier for use to get what you're trying to do. – Dimitris Fasarakis Hilliard Sep 29 '16 at 12:00
  • @Jim Fasarakis-Hilliard i have edited the question. – user1779646 Sep 29 '16 at 12:15

1 Answers1

2

I guess you have to compile the .c file you have obtained.

Assuming you are using python 3.5 and don't have to link to other libraries than python you can do this with a simple gcc command like :

gcc -I /usr/include/python3.5m -o your_program your_file.c -lpython3.5m

(you might need to remove the m following the version number)

As you expect it will use the if __name__ == "__main__": statement as entry-point of the program.

mgc
  • 5,223
  • 1
  • 24
  • 37
  • thanks, but could you explain me what is (m) in lpython3.5m as i can successfully compile with 'm', and what would be effects if remove 'm'. Do i need to have "if__name=__main" as i have already compiled without it? – user1779646 Sep 30 '16 at 22:44
  • The `m` indicates that python was compiled with the support of `PyMalloc`, in a few words a more efficient allocator function than `malloc` system ones (see http://stackoverflow.com/a/16677339/5050917 or https://www.python.org/dev/peps/pep-3149/ for more details). The `if __name__ == "__main__":` isn't mandatory, you can also just let unindented the code you want to be executed when the program starts, exactly as when running it with python. – mgc Oct 01 '16 at 09:14
  • Use `ldconfig -p | grep python3.5` to see the libraries installed on your system. In my case i can see that I only have `libpython3.5m` to link against. – mgc Oct 01 '16 at 09:19
  • gcc -I /usr/include/python3.6 -o hello.c -lpython3.6m does not work for windows. – Tetora Oct 30 '17 at 06:57
  • @HaydenDarcy Yes I have to admit it .. And I dont really have an answer for Windows right now. However the question was explicitly tagged "Linux". – mgc Oct 31 '17 at 08:03