Commit 08187020 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Dynamically load libpython.so before initializing python interpreter.

    This is required in order to make import of module dl succeed.
parent d80c0c34
......@@ -18,7 +18,9 @@
#
INCLUDE(FindPythonLibs)
IF (NOT ${PYTHONLIBS_FOUND} STREQUAL TRUE)
MESSAGE(FATAL_ERROR "Python has not been found.")
MESSAGE(FATAL_ERROR "Python has not been found.")
ELSE()
MESSAGE(STATUS "PYTHON_LIBRARY=${PYTHON_LIBRARY}")
ENDIF (NOT ${PYTHONLIBS_FOUND} STREQUAL TRUE)
INCLUDE(FindPythonInterp)
......@@ -83,7 +85,9 @@ SET_TARGET_PROPERTIES(${PYTHON_MODULE}
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${DYNAMIC_GRAPH_LIBRARIES})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
CONFIG_FILES(link-to-python.hh)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}
${CMAKE_CURRENT_BINARY_DIR})
#
# Installation
......
......@@ -16,6 +16,7 @@
#include <iostream>
#include "dynamic-graph/python/interpreter.hh"
#include "link-to-python.hh"
// Python initialization commands
namespace dynamicgraph {
......@@ -31,9 +32,13 @@ namespace dynamicgraph {
}
using dynamicgraph::python::Interpreter;
using dynamicgraph::python::libpython;
Interpreter::Interpreter()
{
// load python dynamic library
// this is silly, but required to be able to import dl module.
dlopen(libpython.c_str(), RTLD_LAZY | RTLD_GLOBAL);
Py_Initialize();
mainmod_ = PyImport_AddModule("__main__");
Py_INCREF(mainmod_);
......
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
namespace dynamicgraph {
namespace python {
std::string libpython("@PYTHON_LIBRARY@");
} // namespace python
} // namespace dynamicgraph
Supports Markdown
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