diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1ef2110137056b78846af3ad780872cae473bf1..58ea8f4c496af74406286c0815bf724d4421c1e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/interpreter.cc b/src/interpreter.cc index 8d265a98b6dca5847a23d778e7d7c2826ba1f330..3814607b6720b1a8a9f80aa002af27101bde2310 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -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_); diff --git a/src/link-to-python.hh.in b/src/link-to-python.hh.in new file mode 100644 index 0000000000000000000000000000000000000000..d282b4d84420b7695490712ab0f496a7d2857f2f --- /dev/null +++ b/src/link-to-python.hh.in @@ -0,0 +1,27 @@ +// -*- 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