Re: MUD Game Programmming - Python Modules in C++

Discussion in 'Python' started by Gabriel Genellina, Oct 13, 2009.

  1. En Tue, 13 Oct 2009 18:08:53 -0300, Christopher Lloyd
    <> escribió:

    > #include <iostream>
    > #include <string>
    > #include "Python.h"
    >
    > int main()
    > {
    > std::cout << "Starting Python Demo Test" << std::endl;
    >
    > Py_Initialize(); // initialize python
    >
    > std::string str;
    > std::getline( std::cin, str );
    > while( str != "end" )
    > {
    > PyRun_SimpleString( const_cast<char*>( str.c_str() ) );
    > std::getline( std::cin, str );
    > }
    >
    > Py_Finalize(); // shut down python
    > std::cout << "Demo Complete!" << std::endl;
    > return 0;
    > }
    >
    > If I try to compile this in MS Visual C++ 2008 (debug mode), I get the
    > following error:
    >
    > LINK : fatal error LNK1104: cannot open file 'python26_d.lib'


    For a debug build of your program, you require a debug build of Python. A
    release build should compile and link OK with the pre-built Python
    libraries you got, as you already noticed.

    > So, what happens if I try compiling the above C++ in release mode?
    > Actually, nothing - It compiles just fine. However, upon running the
    > resulting program, my command line box displays the following:
    >
    >> Starting Python Demo Test

    >
    > That's all. The program has hung halfway through and the test isn't
    > completed.


    Hung? Or waiting for you to input some Python expression to be evaluated?
    That's what the std::getline( std::cin, str ) line does. Type 2+3 for
    example - you should get the answer.

    > It's been suggested that I replace the first part of my C++ code with
    > the following, and then try to compile in release mode:
    >
    > #ifdef _DEBUG
    > #undef _DEBUG
    > #include <Python.h>
    > #define _DEBUG
    > #else
    > #include <Python.h>
    > #endif


    No, don't do that. Just compile your application in release mode.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 13, 2009
    #1
    1. Advertising

  2. Gabriel Genellina wrote:
    >> #ifdef _DEBUG
    >> #undef _DEBUG
    >> #include <Python.h>
    >> #define _DEBUG
    >> #else
    >> #include <Python.h>
    >> #endif

    [...to keep Python from linking against non-existant debug libraries.]
    >
    > No, don't do that. Just compile your application in release mode.


    Why not, does it break anything?

    Uli

    --
    Sator Laser GmbH
    Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
     
    Ulrich Eckhardt, Oct 14, 2009
    #2
    1. Advertising

  3. En Wed, 14 Oct 2009 05:19:06 -0300, Ulrich Eckhardt
    <> escribió:

    > Gabriel Genellina wrote:
    >>> #ifdef _DEBUG
    >>> #undef _DEBUG
    >>> #include <Python.h>
    >>> #define _DEBUG
    >>> #else
    >>> #include <Python.h>
    >>> #endif

    > [...to keep Python from linking against non-existant debug libraries.]
    >>
    >> No, don't do that. Just compile your application in release mode.

    >
    > Why not, does it break anything?


    You have to ensure the same block is used everywhere <Python.h> is
    included, or remember to always use "mypython.h", but there is still the
    risk when adding some other external library.
    The object layout is different in a debug build, and there are other
    incompatible differences. Mixing code compiled in both modes hopefully
    would generate a linker error, but if not, it may crash the application.
    The debug flag for Python *should* be decoupled from the debug flag for
    the application embedding it, but unfortunately it isn't. There is a
    feature request at http://bugs.python.org (the site doesn't work for me
    now)

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 14, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aditi
    Replies:
    1
    Views:
    357
    Andrew Thompson
    Jul 4, 2005
  2. Discipulus
    Replies:
    1
    Views:
    779
    Jack Diederich
    May 23, 2005
  3. Rythin
    Replies:
    2
    Views:
    296
  4. Rythin
    Replies:
    2
    Views:
    355
  5. Christopher Lloyd

    MUD Game Programmming - Python Modules in C++

    Christopher Lloyd, Oct 13, 2009, in forum: Python
    Replies:
    3
    Views:
    1,084
    Ulrich Eckhardt
    Oct 14, 2009
Loading...

Share This Page