Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

PyBind11 Module ImportError: cannot dynamically load executable

$
0
0

I'm attempting to generate a python module using pybind11, which compiles properly (I think) but when loading the module I get a "cannot dynamically load [position-independent] executable". If I don't use -no-pie I get position-independent as well, but I'm not sure if that's better or worse in this case. My understanding is that I do want a dynamic library but it's not being compiled like that? I'm running python3.10 and g++11.4.0. I'm fairly new to C++ so I have no idea if it's a trivial issue or not.

I've tried changing g++ compiler flags such as -no-pie, -fPIC, -rdynamic, but I don't really know what they do and don't seem to have changed anything except -no-pie. I haven't been able to find any threads describing this problem.

Here's my Makefile:

#!/bin/bashINC=$(shell pybind11-config --includes) -I$(shell pwd)/includeLIB=$(shell python3-config --ldflags)FLAGS=-fPICdefault: mainmain:        # @echo ${INC}        g++ $(FLAGS) $(INC) $(LIB) pymodule.cpp otherfile.cpp -lpython3.10 -o test$(shell python3-config --extension-suffix)

pymodule.cpp:

#include "otherfile.h"#include <iostream>#include <pybind11/pybind11.h>#include <pybind11/numpy.h>void fn() {        std::cout << "fn works" << std::endl;        fn2(); // from otherfile.cpp}int main() {        std::cout << "main works" << std::endl;}PYBIND11_MODULE(test, m){    m.doc() = "Test";    m.def("fn", &fn);}

otherfile.cpp

#include "otherfile.h"#include <iostream>// Has many other includes in actual filevoid fn2() {        std::cout << "fn2 works" << std::endl;}

include/otherfile.h

#ifndef OTHERFILE#define OTHERFILEvoid fn2();#endif

test.py

import test

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>