Opened 17 years ago

Last modified 15 years ago

#543 closed Support Requests (wontfix)

Embedded python won't compile — at Initial Version

Reported by: nobody Owned by: Joel de Guzman
Milestone: Component: python USE GITHUB
Version: None Severity: Problem
Keywords: Cc: dirk@…

Description

I followed the tutorial about embedding at
http://www.boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html#python.using_the_interpreter
but I am now faced with some errors (VC++ 6.0, latest
Service Pack running on Windows 2000 SP4).

The errors:

Compiling...
StdAfx.cpp
Compiling...
pytest.cpp
f:\pytest\pytest.cpp(10) : error C2065: 'object' :
undeclared identifier
f:\pytest\pytest.cpp(10) : error C2146: syntax error :
missing ';' before identifier 'main_module'
f:\pytest\pytest.cpp(10) : error C2065: 'main_module' :
undeclared identifier
f:\pytest\pytest.cpp(11) : error C2065: 'handle' :
undeclared identifier
f:\pytest\pytest.cpp(11) : error C2059: syntax error : '>'
f:\pytest\pytest.cpp(13) : error C2146: syntax error :
missing ';' before identifier 'main_namespace'
f:\pytest\pytest.cpp(13) : error C2065:
'main_namespace' : undeclared identifier
f:\pytest\pytest.cpp(13) : error C2228: left of '.attr'
must have class/struct/union type
f:\pytest\pytest.cpp(15) : error C2059: syntax error : '>'
Error executing cl.exe.

pytest.exe - 9 error(s), 0 warning(s)

The code:

pytest.cpp
==========

// pytest.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"

int main(int argc, char* argv[])
{
	Py_Initialize();

    object main_module((
    handle<>(borrowed(PyImport_AddModule("__main__")))));

object main_namespace = main_module.attr("__dict__");

handle<> ignored((PyRun_String(

    "hello = file('hello.txt', 'w')\n"
    "hello.write('Hello world!')\n"
    "hello.close()"

  , Py_file_input
  , main_namespace.ptr()
  , main_namespace.ptr())
));

	Py_Finalize();

	return 0;
}

StdAfx.cpp
==========

// stdafx.cpp : source file that includes just the
standard includes
//	pytest.pch will be the pre-compiled header
//	stdafx.obj will contain the pre-compiled type
information

#include "stdafx.h"

// TODO: reference any additional headers you need in
STDAFX.H
// and not in this file


StdAfx.h
========

// stdafx.h : include file for standard system include
files,
//  or project specific include files that are used
frequently, but
//      are changed infrequently
//

#if
!defined(AFX_STDAFX_H__14167E34_D56C_4B80_BB18_4CB7F7E8E058__INCLUDED_)
#define
AFX_STDAFX_H__14167E34_D56C_4B80_BB18_4CB7F7E8E058__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used
stuff from Windows headers

#include <stdio.h>
#include "boost\python.hpp"
using namespace std;

// TODO: reference additional headers your program
requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional
declarations immediately before the previous line.

#endif //
!defined(AFX_STDAFX_H__14167E34_D56C_4B80_BB18_4CB7F7E8E058__INCLUDED_)

Libs
====

kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
python24.lib boost_python.lib

Please help, I would VERY much appreciate it- good job
with all the hard work on Boost.Python!

My email address is jamclx@gmail.com

Change History (0)

Note: See TracTickets for help on using tickets.