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?

2
  • what are you trying to do? are you trying to make it importable 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. Commented Sep 29, 2016 at 12:00
  • @Jim Fasarakis-Hilliard i have edited the question. Commented Sep 29, 2016 at 12:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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?
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 stackoverflow.com/a/16677339/5050917 or 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.
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.
gcc -I /usr/include/python3.6 -o hello.c -lpython3.6m does not work for windows.
@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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.