我只是在学用Boost.Python,如果这看起来很傻,请原谅。
我有这些来自here的代码,用python包装c++函数。
我还搜索了几个小时以找到一个有效的例子,最相关的问题是this,但是我仍然在构建和运行方面有问题。在
这是动物园.cpp
#include <boost/python.hpp>
#include <string>
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string hello() {
return std::string("hello, zoo");
}
/*
* This is a macro Boost.Python provides to signify a Python extension module.
*/
BOOST_PYTHON_MODULE(zoo) {
// An established convention for using boost.python.
using namespace boost::python;
// Expose the function hello().
def("hello", hello);
}
和拜访_动物园.py
^{pr2}$这是生成文件
CC = g++
PYLIBPATH = $(shell python-config --exec-prefix)/lib
LIB = -L$(PYLIBPATH) $(shell python-config --libs) -lboost_python
OPTS = $(shell python-config --include) -O2
default: zoo.so
@python ./visit_zoo.py
zoo.so: zoo.o
$(CC) $(LIB) -Wl,-rpath,$(PYLIBPATH) -shared $< -o $@
zoo.o: zoo.cpp Makefile
$(CC) $(OPTS) -c $< -o $@
clean:
rm -rf *.so *.o
.PHONY: default clean
错误信息:
g++ Usage: /usr/bin/python-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--configdir -O2 -c zoo.cpp -o zoo.o
g++: error: Usage:: No such file or directory
g++: error: missing argument to ‘--prefix’
/bin/sh: 1: --exec-prefix: not found
/bin/sh: 1: --includes: not found
/bin/sh: 1: --libs: not found
/bin/sh: 1: --cflags: not found
/bin/sh: 1: --ldflags: not found
/bin/sh: 1: --extension-suffix: not found
/bin/sh: 1: --help: not found
/bin/sh: 1: --configdir: not found
Makefile:13: recipe for target 'zoo.o' failed
make: *** [zoo.o] Error 127
我用了这个有效的makefile。谢谢你的阅读。我得到了here的帮助
相关问题 更多 >
编程相关推荐