[C++-sig] Re: compile errors with embedding example from tutorial

Faheem Mitha faheem at email.unc.edu
Fri Jul 2 23:25:01 CEST 2004

On Fri, 2 Jul 2004 11:48:43 -0500, Chad Austin <caustin at gmail.com> wrote:
> ------=_Part_96_10773503.1088786923701
> Content-Type: text/plain; charset=US-ASCII
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> Heh, I've run into that problem before too.  You may have to do the
> import with PyImport_Import or whatever it is.  (The C equivalent of
> __import__)

You mean use PyImport_Import to import __builtin__? Can you tell me
what the correct syntax for this would be?

> Oddly enough, I'm not seeing any of the problems you are.  See the
> attached files.  Works fine for me.
> Chad at basilisk ~/tmp/bp
> $ scons
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> lude/boost-1_31 -I/usr/include/python2.3 -c -o hello.os hello.cpp
> g++ -shared -o hello.dll hello.os -L/usr/lib/python2.3/config -L/usr/local/lib -
> lboost_python-gcc -lpython2.3
> scons: done building targets.
> Chad at basilisk ~/tmp/bp
> $ python
> Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
> [GCC 3.3.1 (cygming special)] on cygwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import hello
>>>> w = hello.World()
>>>> w.run()
>>>> import os
>>>> os.system('cat hello.txt')
> Hello world!0


I tried using the second Scons file you posted. I had to add `import
sys' at the beginning.

For some reason it builds a file called libhello.so. I renamed it to
hello.so. Do you know why it is generating a file called libhello.so
and how to get it to output to hello.so?

Anyway, I get the same problem with your code as I do with mine,

In [1]: import hello

In [2]: foo = hello.World()

In [3]: foo.run()
NameError                                 Traceback (most recent call



NameError: name 'file' is not defined

I also used Boost.Build and got the same problem. I wonder what is
going on. Possibly some configuration issue with my system. Maybe I
should harass the Debian maintainers of Boost.Python about this. :-)

I figure that it is worth while trying to figure out how to import
__builtin__ somehow. If anyone has specific suggestions about the
syntax, let me know. I'm pretty clueless.

Scons looks cool. The last time I looked at it I didn't know any
Python. Maybe it is time to take a look again.

Thanks for your help.

More information about the Cplusplus-sig mailing list