From f02bd35a46d8e11383aaa1951aca08c892ac704c Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 29 Jun 2021 14:46:47 -0700 Subject: [PATCH 1/2] Fix QIR Simulator dll load Since the packaged Fullstate Simulator always uses the Windows style dll name and local development (or xplat pipelines) need to handle the platform specific library name, we will imitiate the loading patterns from .NET and try both when not on Windows. --- .../Runtime/lib/Simulators/FullstateSimulator.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp index e242cfec42d..9f23e62720c 100644 --- a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp +++ b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp @@ -29,12 +29,11 @@ typedef void* QUANTUM_SIMULATOR; namespace { -#ifdef _WIN32 const char* FULLSTATESIMULATORLIB = "Microsoft.Quantum.Simulator.Runtime.dll"; -#elif __APPLE__ -const char* FULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.dylib"; +#if defined(__APPLE__) +const char* XPLATFULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.dylib"; #else -const char* FULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.so"; +const char* XPLATFULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.so"; #endif QUANTUM_SIMULATOR LoadQuantumSimulator() @@ -52,8 +51,12 @@ QUANTUM_SIMULATOR LoadQuantumSimulator() handle = ::dlopen(FULLSTATESIMULATORLIB, RTLD_LAZY); if (handle == nullptr) { - throw std::runtime_error( - std::string("Failed to load ") + FULLSTATESIMULATORLIB + " (" + ::dlerror() + ")"); + handle = ::dlopen(XPLATFULLSTATESIMULATORLIB, RTLD_LAZY); + if (handle == nullptr) + { + throw std::runtime_error( + std::string("Failed to load ") + XPLATFULLSTATESIMULATORLIB + " (" + ::dlerror() + ")"); + } } #endif return handle; From 41abc204bc877a8e2626952556d42607f70a389e Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 29 Jun 2021 16:34:59 -0700 Subject: [PATCH 2/2] Fix warning as error --- src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp index 9f23e62720c..8724a7b6a3a 100644 --- a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp +++ b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp @@ -32,7 +32,7 @@ namespace const char* FULLSTATESIMULATORLIB = "Microsoft.Quantum.Simulator.Runtime.dll"; #if defined(__APPLE__) const char* XPLATFULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.dylib"; -#else +#elif !defined(_WIN32) const char* XPLATFULLSTATESIMULATORLIB = "libMicrosoft.Quantum.Simulator.Runtime.so"; #endif