Commit 78a5fa46 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding fix for mac for py plugin loader getting nullptr from dlopen


Signed-off-by: Mccaskey, Alex's avatarAlex Mccaskey <mccaskeyaj@ornl.gov>
parent 1b72aa5e
......@@ -6,5 +6,6 @@
#define IBM_TEST_FILE_DIR "${CMAKE_SOURCE_DIR}/quantum/plugins/ibm/tests/test_files"
#define ROERROR_TEST_FILE_DIR "${CMAKE_SOURCE_DIR}/quantum/plugins/decorators/tests/files"
#define GATEIR_TEST_FILE_DIR "${CMAKE_SOURCE_DIR}/quantum/gate/ir/tests/files"
#define ISAPPLE ${APPLE}
#endif
......@@ -40,7 +40,7 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
message(STATUS "HELLO ${PYTHON_LIB_NAME}")
target_include_directories(${LIBRARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}/tpls/pybind11/include)
target_include_directories(${LIBRARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}/tpls/pybind11/include ${CMAKE_BINARY_DIR})
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc Python::Python)
if(APPLE)
......
......@@ -10,7 +10,7 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#include "xacc_config.hpp"
#include "py_plugin_loader.hpp"
#include "pybind11/embed.h"
#include <dlfcn.h>
......@@ -18,13 +18,14 @@ namespace xacc {
namespace external {
bool PythonPluginLoader::load() {
libpython_handle = dlopen("@PYTHON_LIB_NAME@", RTLD_LAZY | RTLD_GLOBAL);
if (!ISAPPLE){
libpython_handle = dlopen("@PYTHON_LIB_NAME@", RTLD_LAZY | RTLD_GLOBAL);
}
guard = std::make_shared<py::scoped_interpreter>();
try {
py::module sys = py::module::import("xacc");
} catch(std::exception& e) {
std::cout << e.what() << "\n";
std::cout << "Could not import " << e.what() << "\n";
return false;
}
......@@ -32,10 +33,13 @@ bool PythonPluginLoader::load() {
}
bool PythonPluginLoader::unload() {
int i = dlclose(libpython_handle);
if (i != 0) {
std::cout << "error closing python lib: " << i << "\n";
return false;
if (!ISAPPLE) {
int i = dlclose(libpython_handle);
if (i != 0) {
std::cout << "error closing python lib: " << i << "\n";
std::cout << dlerror() << "\n";
return false;
}
}
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment