A
A
AlexTeos2016-03-04 10:14:47
Python
AlexTeos, 2016-03-04 10:14:47

How to statically link a Python interpreter?

I have a task: there is some python script, it must be used in a DLL, while minimizing the number of output files as much as possible (preferably to one dll).
So, the python script itself is loaded into the project resources and executed using the Python / C API. The next step, I would like to integrate the python interpreter into my dll.
For this:

  • Downloaded sources ("Solution") Python 2.7.11 from the official site
  • One project selected for compilation - pythoncore
  • Replaced Py_ENABLE_SHARED with Py_NO_ENABLE_SHARED in preprocessor definitions
  • Configuration type changed from DLL (dynamic library) to LIB (static library)
  • The resulting LIB file is added to my project's dependencies
  • Linked the Include folder from the Python sources
  • I copy pyconfig.h from the installed python to the Include folder
  • As far as I know, when compiling my project, statically linked libraries must export their code to the linked library. Accordingly, this LIB file (~15Mb!) is completely self-sufficient (as I understand it).

But when compiling my project, I get errors:
Ошибка 3 error LNK2019: ссылка на неразрешенный внешний символ __imp__Py_Initialize в функции _main E:\7zip\myprogramm\myprogramm\main.obj

The declaration and source code for this function is present in the project - pythoncore.
The platform toolset in both projects is v90. Visual-Studio 2010 environment. Both projects are set to X86.
What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
REDkiy, 2016-03-11
@REDkiy

I would venture to suggest something like this:
stackoverflow.com/questions/9826311/trying-to-unde...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question