Embedded python in C ++ code

Source: Internet
Author: User

 

A simpleProgram:

 

View plaincopy to clipboardprint?
  1. # Include "Boost/python. HPP"
  2. Int_ Tmain (IntArgc, _ tchar * argv [])
  3. {
  4. Py_initialize ();
  5. Pyrun_simplestring ("Print 'hello '");
  6. Py_finalize ();
  7. System ("Pause");
  8. Return0;
  9. }

# Include "Boost/python. HPP "</P> <p> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> py_initialize (); <br/> pyrun_simplestring ("Print 'hello'"); <br/> py_finalize (); <br/> system ("pause"); <br/> return 0; <br/>}< br/>

 

No problem. But I still cannot run it in an XP environment (XP is in a virtual machine, except that the driver is not installed in msdn ). I have installed vc2005 Runtime Library in XP, python26.dll, boost_python-vc80-mt-1_39.dll, boost_python-vc80-mt-gd-1_39.dll are copied to the directory where the program is located or not. The program is released by release. The prompt is displayed as soon as you run the command:


Application initialization (0xc0150002) fails. Click OK to terminate the application.

Google was fruitless for half a day.

 

This morning, I ran a python program packaged in py2exe under xp. Because it is for2.6, We need to install the Runtime Library of vc2008, I ran the C ++ applet yesterday.

But there are still errors. After I pack py2exeand then decompress library.zip to complete the operation! I used python to access the database in C ++, and the operation was also okay!

It seems that it is better to embed Python C ++ programs in the future without vc8 writing. Just use pure C ++.

 

PS: If py2exe is used for packaging, manually redist/x86/Microsoft. all the four files under vc90.crt are copied to the DIST directory generated by the py2exe package. You can directly copy the DIST directory to any environment without Python or 08 runtime libraries installed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.