0

I have a C++ application from Windows that I wish to port across to run on a Red Hat Linux system. This application embeds a slightly modified version of Python 2.7.3 (I added the Py_SetPath command as it is essential for my use case) so I definitely need to compile the Python source.

My problem is that despite looking, I can't actually find any guidance on how to get Python to emit the right files for me to link against and how to then get g++ to link my C++ code against it in such a way that I don't need to have an installed copy of Python on every system I distribute this to.

So my questions are:

  • how do I compile Python so that it can be embedded into the C++ app on Linux?
  • what am I linking against for the C++ app to work?

Sorry for these basic questions, but having convinced my employer to let me try and move our systems over to Linux, I'm keen to make it go off as smoothly as possible and I'm worried avbout not making too much progress!

1 Answer 1

1

You want to link to the python static library, which should get created by default and will be called libpython2.7.a

If I recall correctly, as long as you don't build Python with --enable-shared it doesn't install the dynamic library, so you'll only get the static lib and so simply linking your C++ application with -lpython2.7 -L/path/where/you/installed/python/lib should link to the static library.

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

2 Comments

Thanks for that - will give it a go and let you know
Had a try - code compiles, but now getting a Segmentation Fault when I try to run it - fun to debug, I'm sure :-S Anyway, this answered the question.

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.