• Module use of python3_d.dll conflicts with this version of Python

    From Olivier B.@21:1/5 to All on Thu Jan 26 14:11:12 2023
    Hi,I am in the process of trying to make my code (an c++ executable
    and swig modules using the Python C API) lose the dependency to python
    3.7, to be compatible with all Python 3.2+

    I tried linking to python.lib instead of python37.lib. As i am still
    using a few things that are not in the limited API, my binaries now
    have a dependency to python3.dll for the base stuff, and pyhton37.dll
    for the few symbols that are not backwards compatible.

    In release, that does not seem to bring issues. In debug (debug build
    of my program that uses python debug build) however, when the process
    is importing the swig python/c++ module, i get a
    "Module use of python3_d.dll conflicts with this version of Python". I
    checked that i am properly loading the python3_d.dll of my python37,
    and python python37_d.dll too

    Looking in dynload_win.c of python sources where the message is
    triggered, indeed it is comparing in py case python37_d.dll to
    python3_d.dll.
    And i guess, in release, it works because in GetPythonModule(), there' is

    #ifndef _DEBUG
    /* In a release version, don't claim that python3.dll is
    a Python DLL. */
    if (strcmp(import_name, "python3.dll") == 0) {
    import_data += 20;
    continue;
    }
    #endif

    Does someone know why it would have been chosen to be different for
    debug builds?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eryk Sun@21:1/5 to Olivier B. on Thu Jan 26 16:55:05 2023
    On 1/26/23, Olivier B. <perso.olivier.barthelemy@gmail.com> wrote:

    Does someone know why it would have been chosen to be different for
    debug builds?

    It's assumed that a debug build would normally link with
    "pythonXY_d.dll". Maybe it should be more defensive. Refer to the
    following setup in PC/pyconfig.h:

    /* For an MSVC DLL, we can nominate the .lib files used by extensions */
    #ifdef MS_COREDLL
    # if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
    /* 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.) */
    # if defined(_DEBUG)
    # pragma comment(lib,"python312_d.lib")
    # elif defined(Py_LIMITED_API)
    # pragma comment(lib,"python3.lib")
    # else
    # pragma comment(lib,"python312.lib")
    # endif /* _DEBUG */
    # endif /* _MSC_VER */
    # endif /* Py_BUILD_CORE */
    #endif /* MS_COREDLL */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)