I'm trying to embed Python in a C++Builder application for Windows.
After many research on the subject (example), I have found the Python4Delphi project that seems very interesting and exactly what I'm trying to do. The thing is that I'm not using Delphi (and I don't really want to use it) but only C++Builder.
I have also found some examples to embed Python in C++ projects (example), so I am trying this method. The problem is I can not compile even the first simple "Hello world" example.
Here are the steps I followed:
- Creating in C++ builder a New console application project
- Include Python.h files
- compile the following code:
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include <conio.h>
#include <Python.h>
int main()
{
PyObject* pInt;
Py_Initialize();
PyRun_SimpleString("print('Hello World from Embedded Python!!!')");
Py_Finalize();
printf("\nPress any key to exit...\n");
if(!_getch()) _getch();
return 0;
}
During the compilation I am getting the following error multiples times:
[bcc32c Error] pymath.h(22): declaration conflicts with target of using declaration already in scope.
This happens, for example, when line 22 from pymath.h
is compiled:
#ifndef HAVE_ROUND
extern double round(double);
#endif
I think it probably comes because of compiler and/or pyconfig.h
configuration. As a beginner in C++ and this king of thing, it is difficult for me to solve this problem.
Can you help me, do you have any suggestion?
EDIT
Since April 2020, C++Builder seems to support the Boost library, which can be used to implement Python in a C++ program. So the previous errors no longer appear, instead I have a different error.
Using the same script as before, but using #include <boost/Python.hpp>
, I have the error:
[ilink32 Error] Fatal: Impossible to open the file 'LIBBOOST_PYTHON38-BCB32C-MT-S-X32-1_68.LIB'
Do you have an idea to solve this problem?