编译 Caffe:对 `PyString_FromString' 的未定义引用

Compiling Caffe: undefined reference to `PyString_FromString'

我正在尝试从官方 GitHub 来源编译 Caffe + 使用用户添加的几个层 cpp 文件。编译时出现以下错误:

f@f-VirtualBox:~/caffe/mts4/caffe-master$ sudo make all
CXX/LD -o .build_release/tools/caffe.bin
.build_release/lib/libcaffe.so: undefined reference to `PyString_FromString'
.build_release/lib/libcaffe.so: undefined reference to `PyErr_Print'
.build_release/lib/libcaffe.so: undefined reference to `PyObject_CallObject'
.build_release/lib/libcaffe.so: undefined reference to `PyInt_FromLong'
.build_release/lib/libcaffe.so: undefined reference to `PyList_SetItem'
.build_release/lib/libcaffe.so: undefined reference to `PyCallable_Check'
.build_release/lib/libcaffe.so: undefined reference to `PyImport_Import'
.build_release/lib/libcaffe.so: undefined reference to `Py_Initialize'
.build_release/lib/libcaffe.so: undefined reference to `PyFloat_AsDouble'
.build_release/lib/libcaffe.so: undefined reference to `PyTuple_SetItem'
.build_release/lib/libcaffe.so: undefined reference to `PyObject_GetAttrString'
.build_release/lib/libcaffe.so: undefined reference to `PyList_New'
.build_release/lib/libcaffe.so: undefined reference to `PyTuple_New'
.build_release/lib/libcaffe.so: undefined reference to `PyErr_Occurred'
collect2: error: ld returned 1 exit status
Makefile:560: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1
f@f-VirtualBox:~/caffe/mts4/caffe-master$ 

编译错误意味着至少有一些用户添加或更改的cpp文件使用了Python。要解决此问题,您应该在编译前取消注释 Makefile.config 中的 WITH_PYTHON_LAYER := 1