From 1cfe7b10baa182a8acde7f6d24e471a1d68b9339 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 28 Mar 2023 00:39:32 +0200 Subject: [PATCH] Another attempt trying to fix the DLL load issue for pya on Windows - force-load all DLL that are needed by pyacore into the app before importing the module --- src/klayout_main/klayout_main/klayout.cc | 2 + .../klayout_main/klayout_main.pro | 49 ------------------- src/pya/pya/pya.cc | 12 ----- src/unit_tests/unit_test_main.cc | 34 +++++++++++++ src/with_all_libs.pri | 49 +++++++++++++++++++ 5 files changed, 85 insertions(+), 61 deletions(-) diff --git a/src/klayout_main/klayout_main/klayout.cc b/src/klayout_main/klayout_main/klayout.cc index f813f404b..c679c5536 100644 --- a/src/klayout_main/klayout_main/klayout.cc +++ b/src/klayout_main/klayout_main/klayout.cc @@ -65,6 +65,8 @@ # include "gsiQtDesignerExternals.h" # include "gsiQtUiToolsExternals.h" +// pulls in the Qt GSI binding modules - need to be force loaded so they are available +// the pya Python module (Python >= 3.8 does not recognize DLL paths on Windows) FORCE_LINK_GSI_QTCORE FORCE_LINK_GSI_QTGUI FORCE_LINK_GSI_QTWIDGETS diff --git a/src/klayout_main/klayout_main/klayout_main.pro b/src/klayout_main/klayout_main/klayout_main.pro index 45bad98c2..03a31a4cb 100644 --- a/src/klayout_main/klayout_main/klayout_main.pro +++ b/src/klayout_main/klayout_main/klayout_main.pro @@ -25,52 +25,3 @@ INCLUDEPATH += $$DOC_INC $$ICONS_INC $$QTBASIC_INC DEPENDPATH += $$DOC_INC $$ICONS_INC $$QTBASIC_INC LIBS += -lklayout_doc -lklayout_icons - -equals(HAVE_QTBINDINGS, "1") { - - LIBS += -lklayout_qtbasic -lklayout_QtGui - - !equals(HAVE_QT_XML, "0") { - LIBS += -lklayout_QtXml - } - !equals(HAVE_QT_NETWORK, "0") { - LIBS += -lklayout_QtNetwork - } - !equals(HAVE_QT_SQL, "0") { - LIBS += -lklayout_QtSql - } - !equals(HAVE_QT_DESIGNER, "0") { - LIBS += -lklayout_QtDesigner - } - !equals(HAVE_QT_UITOOLS, "0") { - LIBS += -lklayout_QtUiTools - } - - greaterThan(QT_MAJOR_VERSION, 4) { - - LIBS += -lklayout_QtWidgets - - !equals(HAVE_QT_MULTIMEDIA, "0") { - LIBS += -lklayout_QtMultimedia - } - !equals(HAVE_QT_PRINTSUPPORT, "0") { - LIBS += -lklayout_QtPrintSupport - } - !equals(HAVE_QT_SVG, "0") { - LIBS += -lklayout_QtSvg - } - !equals(HAVE_QT_XML, "0") { - LIBS += -lklayout_QtXmlPatterns - } - - } - - greaterThan(QT_MAJOR_VERSION, 5) { - - LIBS += -lklayout_QtCore5Compat - LIBS -= -lklayout_QtXmlPatterns - LIBS -= -lklayout_QtDesigner - - } - -} diff --git a/src/pya/pya/pya.cc b/src/pya/pya/pya.cc index 45c4a6fa1..38fd8e5c1 100644 --- a/src/pya/pya/pya.cc +++ b/src/pya/pya/pya.cc @@ -326,18 +326,6 @@ PythonInterpreter::PythonInterpreter (bool embedded) tl::warn << tl::to_string (tr ("Unable to find built-in Python module library path")); } - // Supply a DLL load path for certain Python versions and on Windows - define_variable ("__klayout_dll_path", tl::dirname (app_path)); - // NOTE: there is no API I know of ... - eval_string ( - "import os\n" - "try:\n" - " global __klayout_dll_path\n" - " os.add_dll_directory(__klayout_dll_path)\n" - "except:\n" - " pass\n" // on Windows or older versions of Python - ); - // Import the pya module PyObject *pya_module = PyImport_ImportModule (pya_module_name); if (pya_module == NULL) { diff --git a/src/unit_tests/unit_test_main.cc b/src/unit_tests/unit_test_main.cc index 75c8f7809..c7ac22612 100644 --- a/src/unit_tests/unit_test_main.cc +++ b/src/unit_tests/unit_test_main.cc @@ -80,6 +80,40 @@ # include "lvsForceLink.h" #endif +#if defined(HAVE_QTBINDINGS) + +// pulls in the Qt GSI binding modules - need to be force loaded so they are available +// the pya Python module (Python >= 3.8 does not recognize DLL paths on Windows) +# include "gsiQtGuiExternals.h" +# include "gsiQtWidgetsExternals.h" +# include "gsiQtCoreExternals.h" +# include "gsiQtMultimediaExternals.h" +# include "gsiQtPrintSupportExternals.h" +# include "gsiQtXmlExternals.h" +# include "gsiQtXmlPatternsExternals.h" +# include "gsiQtSqlExternals.h" +# include "gsiQtSvgExternals.h" +# include "gsiQtNetworkExternals.h" +# include "gsiQtDesignerExternals.h" +# include "gsiQtUiToolsExternals.h" + +FORCE_LINK_GSI_QTCORE +FORCE_LINK_GSI_QTGUI +FORCE_LINK_GSI_QTWIDGETS +FORCE_LINK_GSI_QTMULTIMEDIA +FORCE_LINK_GSI_QTPRINTSUPPORT +FORCE_LINK_GSI_QTXML +FORCE_LINK_GSI_QTXMLPATTERNS +FORCE_LINK_GSI_QTDESIGNER +FORCE_LINK_GSI_QTNETWORK +FORCE_LINK_GSI_QTSQL +FORCE_LINK_GSI_QTSVG +FORCE_LINK_GSI_QTUITOOLS + +#else +# define QT_EXTERNAL_BASE(x) +#endif + static int main_cont (int &argc, char **argv); #ifdef _WIN32 // for VC++ diff --git a/src/with_all_libs.pri b/src/with_all_libs.pri index 72085c5a7..c1c4812b9 100644 --- a/src/with_all_libs.pri +++ b/src/with_all_libs.pri @@ -29,6 +29,55 @@ equals(HAVE_PYTHON, "1") { LIBS += -lklayout_pyastub } +equals(HAVE_QTBINDINGS, "1") { + + LIBS += -lklayout_qtbasic -lklayout_QtGui + + !equals(HAVE_QT_XML, "0") { + LIBS += -lklayout_QtXml + } + !equals(HAVE_QT_NETWORK, "0") { + LIBS += -lklayout_QtNetwork + } + !equals(HAVE_QT_SQL, "0") { + LIBS += -lklayout_QtSql + } + !equals(HAVE_QT_DESIGNER, "0") { + LIBS += -lklayout_QtDesigner + } + !equals(HAVE_QT_UITOOLS, "0") { + LIBS += -lklayout_QtUiTools + } + + greaterThan(QT_MAJOR_VERSION, 4) { + + LIBS += -lklayout_QtWidgets + + !equals(HAVE_QT_MULTIMEDIA, "0") { + LIBS += -lklayout_QtMultimedia + } + !equals(HAVE_QT_PRINTSUPPORT, "0") { + LIBS += -lklayout_QtPrintSupport + } + !equals(HAVE_QT_SVG, "0") { + LIBS += -lklayout_QtSvg + } + !equals(HAVE_QT_XML, "0") { + LIBS += -lklayout_QtXmlPatterns + } + + } + + greaterThan(QT_MAJOR_VERSION, 5) { + + LIBS += -lklayout_QtCore5Compat + LIBS -= -lklayout_QtXmlPatterns + LIBS -= -lklayout_QtDesigner + + } + +} + equals(HAVE_RUBY, "1") { # DRC is only available with Ruby INCLUDEPATH += $$DRC_INC $$LVS_INC