- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
最近在学习boost C++库。我想用 python 调用现有的 C++ 项目。我已经使用 brew install boost
在 OSX 10.11 下安装了 boost。我的 python 版本 2.7。
我做了一个 hello.c:
char const* greet()
{
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello)
{
using namespace boost::python;
def("greet", greet);
}
和生成文件:
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
#
BOOST_INC = /usr/local/include
BOOST_LIB = /usr/local/lib
#
# compile mesh classes
TARGET = hello
$(TARGET).so: $(TARGET).o
g++ -shared -Wl $(TARGET).o -L$(BOOST_LIB) -lboost_python -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
$(TARGET).o: $(TARGET).c
g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).c
但是,在我运行 make
并得到 hello.so 之后。我在运行 python 代码时遇到以下错误:
import hello
print hello.greet()
错误:
Traceback (most recent call last):
File "test.py", line 4, in <module>
import hello
ImportError: dlopen(/Users/einverne/boost_test/hello.so, 2): Library not loaded: libboost_python.dylib
Referenced from: /Users/einverne/boost_test/hello.so
Reason: unsafe use of relative rpath libboost_python.dylib in /Users/einverne/boost_test/hello.so with restricted binary
最佳答案
拿这个link作为引用。
对于我的问题,使用 otool -L hello.so
:
hello.so:
hello.so (compatibility version 0.0.0, current version 0.0.0)
libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
可以看到libboost_python.dylib并没有指向真正存在的路径。
所以使用这个命令:
install_name_tool -change libboost_python.dylib /usr/local/lib/libboost_python.dylib hello.so
然后再次运行otool -L hello.so
:
hello.so:
hello.so (compatibility version 0.0.0, current version 0.0.0)
/usr/local/lib/libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
最后运行python test.py
,我得到了结果。
关于python - 在制作 boost.python helloword 演示时不安全地使用相对 rpath libboost.dylib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281753/
现在我正尝试在我的项目中使用 libboost-regex。但是我有点困惑,因为下面有一些相关的库。我只想使用 boost-regex。那么在那种情况下,安装 libboost-regex 的最佳方法
我正在尝试在 Centos7 中安装 ContextBroker: sudo rpm -i contextBroker-0.14.1-1.X86_64.rpm 但是我遇到了下一个错误: error:
我正在尝试在 ASIO 中实现一个简单的客户端/服务器。 我想要服务器端的以下内容: onConnect() onDisconnect() onMessageRecieved(char* 数据) se
我已经通过apt-get安装了libboost-dev,它放在/usr/lib中。 /usr/lib$ ls | grep boost libboost_filesystem.so.1.46.1 li
我正在尝试运行外部 shell 命令并使用 C++ 的 Boost 库读取其输出,但似乎该命令未运行或我无法访问输出。我正在使用 their documentation举个例子,这样写: #inclu
我正在学习一些教程,这些教程解释了我应该添加 libboost_chrono-vc140-mt-gd-1_62.lib 作为我的程序将与之链接的库。我遇到的问题是 IDK 在 Visual Studi
我有一个 debian/control 文件,其中包括: Build-Depends: ... libboost1.35-dev, libboost-date-time1.35-dev, ... 这会
我看到以下错误 ImportError: /usr/local/lib/libboost_python.so.1.57.0: undefined symbol: PyUnicode_AsUTF8Str
我正在 Linux Mint 上重新编译一些使用 libboost 的 C++ 代码。从 Mint 18 升级到 Mint 19.3 之前,代码运行良好。从那时起,我可以编译代码,但在执行过程中,它会
我刚刚安装了 boost 1.62 并使用 --log_sink=output.xml 运行了 boost 单元测试选项,但我得到了一个错误。 这是我的命令行 ./App --log_level=te
我正在尝试在 Ubuntu 11.04 x64 上构建 32 位应用程序。由于 libboost 的链接器错误,我在构建时遇到了一些问题。构建语句中有 -lboost_system,但是当我尝试构建时
我正在尝试编译 msp430 debug stack在 OpenSUSE 上。已安装所有先决条件。当我使用静态链接选项运行它时,链接器说: _filesystem -lboost_date_time
我在我的设备中运行了 flutter 的示例代码。我得到一个日志: 2019-03-28 10:07:18.105 6794-6819/com.example.ijkplayer_example E/
在 Ubuntu 上有一个安装 boost 库的命令是这样的: sudo apt-get install libboost-all-dev 这个命令是否也安装和编译只有头文件的库? 如果没有,我还需要
我在我的项目中使用了 boost。我从这里下载了预编译的二进制文件 http://boost.teeks99.com/ 链接时我收到这样的错误: 错误 18 error LNK2005: "publi
我正在尝试使用 Ubuntu 9.04 存储库在 Ubuntu 8.10 中安装 libboost 1.38,因为它在任何 8.10 存储库中都不可用。我正在尝试通过添加以下代码行来使用 Apt-pi
我正在 Ubuntu 14.04 计算机上按照以下步骤安装 HHVM。 https://www.digitalocean.com/community/articles/how-to-install-h
有没有办法在 Ubuntu 8.10 上安装 Libboost 1.38?我存储库中的最高版本是 1.35。有人建议我可以添加一些存储库来完成此操作,但我的搜索没有产生任何结果。 我必须求助于源代码吗
我正在尝试使用 OS Raspbian Jessie 在树莓派 2 上编译 Ocelot 跟踪器。我已经从 apt 安装了 libboost1.55-dev-all 库。编译时出现多个错误:“对 `b
最近在学习boost C++库。我想用 python 调用现有的 C++ 项目。我已经使用 brew install boost 在 OSX 10.11 下安装了 boost。我的 python 版本
我是一名优秀的程序员,十分优秀!