pybind11
pybind11 copied to clipboard
[BUG]: Link Error
Required prerequisites
- [X] Make sure you've read the documentation. Your issue may be addressed there.
- [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- [ ] Consider asking first in the Gitter chat room or in a Discussion.
Problem description
How to use my own link library in pybind11??
here is the example code:
test1.h
int add(int a, int b);
test1.cpp
int add(int a, int b){
return a+b;
}
test2.cpp
#include "test1.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;
int add2(int a, int b){
return add(a, b)+add(a,b);
}
PYBIND11_MODULE(example, m) {
m.doc() = "test extra link";
m.def("add2", &add2, "A function which adds two numbers");
}
firstly, I make test1 to a link library. Then, I use setup.py to make the module.
setup.py
from pybind11.setup_helpers import Pybind11Extension, build_ext
import setuptools
library_dirs = ["./"]
def get_extensions():
ext_modules = [Pybind11Extension('example',
['test2.cpp'],
extra_compile_args=['-Xlinker','-export-dynamic'],
extra_link_args = ['-L{} -ltest1'.format(library_dirs[0])],
cxx_std=11),]
return ext_modules
setuptools.setup(
name='example',
ext_modules=get_extensions(),
cmdclass={'build_ext': build_ext},
classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
packages=setuptools.find_packages(),
)
here is the Error:
when I ldd the .so get this:
It seems that didn't link the test1.so
Reproducible example code
No response
This is often because the version of Python that is running is not the version it was compiled against.
This is often because the version of Python that is running is not the version it was compiled against.
If so, why I ldd the final .so can't find the libtest1.so?
I had the same issue and forcing a reinstall of pybind11-global
via conda-forge seems to have fixed it (conda install -c conda-forge pybind11-global). But I have a hard time reproducing the problem...