问题描述
我正在关注https://pybind11.readthedocs.io/en/master/basics.html。
我做了make check -j 4
。我在〜/ ckim / PYBIND11 / pybind11,现在我看到pybind11目录(〜/ ckim / PYBIND / pybind11 / pybind11)生成了,在该目录下有__init__.py和__main__.py以及其他内容。
这是example.cpp文件(在〜/ ckim / PYBIND11 / pybind11中)。
#include <pybind11/pybind11.h>
namespace py = pybind11;
int add(int i,int j) {
return i + j;
}
PYBIND11_MODULE(example,m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add",&add,"A function which adds two numbers");
}
和example.py文件(也在〜/ ckim / PYBIND11 / pybind中):
#! /usr/bin/env python3.5
import example
r = example.add(2,3)
print(r)
我运行命令:
c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` example.cpp -o example.so
运行正常。
ckim@chan-ubuntu:~/PYBIND11/pybind11$ python3 example.py
5
我的问题是:
当我通过添加打印来更改pybind11 / __ init__.py文件时,编译器给了我错误。(第print(os.path.dirname(__file__))
行)
# -*- coding: utf-8 -*-
from ._version import version_info,__version__ # noqa: F401 imported but unused
def get_include(user=False):
import os
d = os.path.dirname(__file__)
print(os.path.dirname(__file__))
if os.path.exists(os.path.join(d,"include")):
# Package is installed
return os.path.join(d,"include")
else:
# Package is from a source directory
return os.path.join(os.path.dirname(d),"include")
当我运行c ++命令时,错误是这样的
ckim@chan-ubuntu:~/PYBIND11/pybind11$ !c++
c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` example.cpp -o example.so
/usr/bin/ld: cannot find /home/ckim/PYBIND11/pybind11/pybind11: File format not recognized
collect2: error: ld returned 1 exit status
是什么原因? (没有打印,可以)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)