Linking debug C++ DLL with python dlls

M

moshehaim1

Hi,

I am working with C++ code that needs to be maintained both in debug
and release versions. The environment is Windows 32 bit with MSVC8.

I downloaded the python installation for Win32 and installed it.
When, however, I tried to compile my DLLs in debug mode i got link
errors specifying that I need the python25_d.lib.

this is the code that generates the dependency on the python25_d.lib
in the <pyconfig.h>
#ifdef MS_COREDLL
# ifndef Py_BUILD_CORE /* not building the core - must be an ext */
# if defined(_MSC_VER)
/* So MSVC users need not specify the .lib file in
their Makefile (other compilers are generally
taken care of by distutils.) */
# ifdef _DEBUG
# pragma comment(lib,"python25_d.lib")
# else
# pragma comment(lib,"python25.lib")
# endif /* _DEBUG */
# endif /* _MSC_VER */
# endif /* Py_BUILD_CORE */
#endif /* MS_COREDLL */

So I decided to download and build the debug version of python2.5.1/
As it seems I also need to compile all relevant extension modules
(*.pyd) in debug as well - is this correct?

I tried to change the code above (just for fun) so in both cases i'll
use python25.lib and in debug compilation I got linker errors on
unresolved externals. seems like the debug version exports more
methods than the release version.

Is there a way to have my C++ code compile in debug mode (with _DEBUG)
but use the python25 release lib/dll? This way I don't need to have
additional set of debug extension modules.

Thanks,
Moshe.
 
B

brzrkr0

I tried to change the code above (just for fun) so in both cases i'll
use python25.lib and in debug compilation I got linker errors on
unresolved externals. seems like the debug version exports more
methods than the release version.

I usually just build my extensions in release mode and avoid using the
debugger. Getting a copy of python24_d.lib (in my case) and building
a debug version of my extension isn't a big deal, but afaik all my
other extensions (wxPython, numpy, etc) have to be built in debug mode
as well in order for things to work.

If you find a good solution, please post it to the group because I'd
like to know how to do this as well.

-Casey
 
M

Mathieu Gontier

Hello,

I often build Python on Windows.

What I can say is it not so trivial to build debug libraries for Python:
each debug library must have the postfix *_d.dll/.pyd.

Another useful information. On Windows, a shared library is linked to
our application though a associated file with the .lib extension. This
"static library" contains all the information relating to de
__declspec(import) / __declspec(export) instructions you should add in
the code. The most important in Python is that the shared libraries
(usually with the extension .dll) have as extension .pyd.
So, you can change it in Visual Studio.


Mathieu Gontier
Core Development Engineer

Read the attached v-card for telephone, fax, adress
Look at our web-site http://www.fft.be
 
?

=?ISO-8859-8-I?Q?=22Martin_v=2E_Lo=22wis=22?=

So I decided to download and build the debug version of python2.5.1/
As it seems I also need to compile all relevant extension modules
(*.pyd) in debug as well - is this correct?

That's correct.
I tried to change the code above (just for fun) so in both cases i'll
use python25.lib and in debug compilation I got linker errors on
unresolved externals. seems like the debug version exports more
methods than the release version.
Correct.

Is there a way to have my C++ code compile in debug mode (with _DEBUG)
but use the python25 release lib/dll? This way I don't need to have
additional set of debug extension modules.

Try removing the definition of Py_DEBUG that is implied by _DEBUG.

Notice, however, that it is risky to mix different CRT versions
(debug and nodebug) in a single application; this could cause memory
leaks and crashes. In particular, it *will* cause crashes if you
pass FILE* opened by the debug CRT to PyRun_File and friends. That's
an inherent limitation of Windows DLLs, and the way Microsoft set
up global variables in the VC CRT.

Regards,
Martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top