You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having a very odd issue when trying to embed the interpreter into my C++ program and cannot seem to find any kind of solution. I'm hoping someone here can help.
I have an OpenGL application, which links to three shared libs that I wrote, libA, libB, and libSDLWindow
All are compiled as shared objects. libSDLWindow also privately links to libSDL2.so
I'm trying to embed the interpreter into my C++ code, but I'm getting odd behaviour when I
link to libSDLWindow.so. (this is just shared lib that helps me create SDL Windows for rendering)
In the code below, if I do not include auto sdlWindow = std::make_shared<SDLWindow>();, gcc wont link
libSDL2.so to the final exe, and the python code executes properly.
If I keep the code in and libSDL2.so is linked with my application, the py::exec line will core dump.
This only happens when i'm importing the numpy library. If I remove the numpy import, everything works fine
I'm not sure why libSDL2.so is somehow conflicting with the import numpy.
Some Notes:
The core dump occurs on the py::exec call not on the auto sdlWindow = std::make_shared<SDLWindow>();
I'm using python 3.6 on Ubuntu 18.04. Numpy is installed via pip3 and is located in the user's home directory.
I don't think the problem is with numpy, it seems to be any python lib that's not the standard libraries
Standard libraries seem to import fine.
libA and libB do not seem to cause any issues, just the sdlWindow library
#include<libA.h>
#include<libB.h>
#include<SDLWindow.h>// built as shared lib, links to libSDL2.so
#include<pybind11/pybind11.h>
#include<pybind11/embed.h>namespacepy= pybind11;
intmain(int argc, char ** argv)
{
py::initialize_interpreter();
py::exec(R"( import numpy import sys kwargs = dict(name="World", number=42) message = "Hello, {name}! The answer is {number}".format(**kwargs) print(message) print(sys.path) print(numpy.array([1,2,3,4])))");
// Comment this line, and py::exec will work// leave it in, py::exec will abort with (core dumped)//// not calling py::exec will not cause a crashauto sdlWindow = std::make_shared<SDLWindow>();
auto A = std::make_shared<classA>();
auto B = std::make_shared<classB>();
py::finalize_interpreter();
return0;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm having a very odd issue when trying to embed the interpreter into my C++ program and cannot seem to find any kind of solution. I'm hoping someone here can help.
I have an OpenGL application, which links to three shared libs that I wrote, libA, libB, and libSDLWindow
All are compiled as shared objects. libSDLWindow also privately links to libSDL2.so
I'm trying to embed the interpreter into my C++ code, but I'm getting odd behaviour when I
link to
libSDLWindow.so
. (this is just shared lib that helps me create SDL Windows for rendering)In the code below, if I do not include
auto sdlWindow = std::make_shared<SDLWindow>();
, gcc wont linklibSDL2.so to the final exe, and the python code executes properly.
If I keep the code in and libSDL2.so is linked with my application, the py::exec line will core dump.
This only happens when i'm importing the
numpy
library. If I remove the numpy import, everything works fineI'm not sure why libSDL2.so is somehow conflicting with the
import numpy
.Some Notes:
py::exec
call not on theauto sdlWindow = std::make_shared<SDLWindow>();
Beta Was this translation helpful? Give feedback.
All reactions