Autodesk / maya-usd

A common USD (Universal Scene Description) plugin for Autodesk Maya
761 stars 202 forks source link

Python related link error with --build-debug on Windows. #2619

Open jjzanin opened 1 year ago

jjzanin commented 1 year ago

Describe the issue There is a link error when specifying the "--build-debug" commandline option to the build.py script when building on Windows (not tested on other platforms):

python.exe build.py --generator="Visual Studio 16 2019" --install-location %INSTALL_LOCATION% --maya-location "%MAYA_BASE_LOCATION%\Maya" --pxrusd-location "..\..\USD\Debug" --devkit-location "%MAYA_BASE_LOCATION%\Maya" --qt-location c:\usr\bin\qt\5.15.2\v141 --build-debug --build-args="-DUSD_LIB_PREFIX=pxrdbg_,-DBUILD_WITH_PYTHON_3=ON" ..\

LINK : fatal error LNK1104: cannot open file 'python39_d.lib'

The issue is that when _DEBUG is defined, pyconfig.h will inject the pythonXX_d.lib, for example:

#if defined(_DEBUG)
#    pragma comment(lib,"python39_d.lib")
#elif defined(Py_LIMITED_API)
#    pragma comment(lib,"python3.lib")
#else
#    pragma comment(lib,"python39.lib")
#endif /* _DEBUG */

It appears that the MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG is supposed to control whether to enable BOOST_DEBUG_PYTHON or not. When BOOST_DEBUG_PYTHON is not defined, _DEBUG is undefined in "wrap_python.hpp", so the non-debug version of the python library is injected. The "CMakeLists.txt" files only check for the build configuration (CMAKE_BUILD_TYPE) when determining if BOOST_DEBUG_PYTHON is defined and does not check MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG:

$<$<STREQUAL:${CMAKE_BUILD_TYPE},Debug>:BOOST_DEBUG_PYTHON>

I don't know if this is a proper fix, but this is what I changed it to in all the CMakeLists.txt files, and it fixes the link error when MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG is off:

$<$<AND:$<STREQUAL:${CMAKE_BUILD_TYPE},Debug>,$<STREQUAL:${MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG},ON>>:BOOST_DEBUG_PYTHON>

The link error still happens if you also specify "--debug-python" to the build.py script, which turns on MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG.

Build log build_log.txt is attached

Specs: Windows 10 Enterprise, version 21H1 Visual Studio 2019 Maya 2023 Maya USD commit SHA: 0.19.0, master at a2fdf40 Pixar USD commit SHA: 22.08, release at 3abc464

seando-adsk commented 1 year ago

When building in Debug we also want to build against a debug version of Python. Internally when building MayaUsd we give the plugin build the python from Maya (we have a debug build of Maya with a debug python).

Unfortunately for you there is no official python install package in Debug (as there are many options that can be selected). One option is to build Python yourself.

An easier solution for you if you want to debug the plugin in RelWithDebInfo is to add the /O0 flag (optimization level zero). This will produce binaries that are easier to debug.

Sean

jjzanin commented 1 year ago

When specifying "--build-debug" only, should BOOST_DEBUG_PYTHON defined? The code in "build.py" seems to indicate no, but I'm probably not understanding correctly:

        # Many people on Windows may not have python with the 
        # debugging symbol (python27_d.lib) installed, this is the common case.
        if context.buildDebug and context.debugPython:
            extraArgs.append('-DMAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG=ON')
        else:
            extraArgs.append('-DMAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG=OFF')

MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG is only turned on when "--build-debug" and "--debug-python" are both specified.

When BOOST_DEBUG_PYTHON is defined in the CMakeLists.txt files because only "Debug" is checked, boost will auto-link the debug version of the python library but the linker input dependency is the non-debug version and there is no additional library path for the linker to find the debug version, so you get a linker error.

I do have python39_d.lib/.dll and I am unable to link against it when using "--build-debug" and "--debug-python" because the linker input dependency is incorrect (using the non-debug version) and/or the library path isn't specified.

maya-usd-git-sync[bot] commented 10 months ago

Issue synced internally to EMSUSD-726