Protobuf Python 找不到包含

protobuf python can't find include

本文关键字:包含 找不到 Python Protobuf      更新时间:2023-10-16

我注意到其他一些人有问题,我看到的唯一解决方案是CXXFLAGSLDFLAGS,但它们似乎不起作用。

尝试为替代Python版本编译C++protobuff我使用virtualenv在CentOS上编译并安装在一个用户帐户上:

$ cd ~/myApp
$ /opt/python-2.7/bin/virtualenv python
$ source ~/myApp/python/bin/activate
(python)$ cd ~/src/protobuf-2.5.0
(python)$ ./configure --prefix=$HOME/usr
(python)$ make && make install

弹出一条消息:


库已安装在:/home/myuser/usr/lib

如果您碰巧想要链接到已安装的库在给定的目录LIBDIR中,必须使用libtool,并且指定库的完整路径名,或使用-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the LD_library_PATH环境变量执行期间-将LIBDIR添加到LD_RUN_PATH' environment variable during linking - use the-Wl、-rpath-Wl、LIBDIR的链接器标志中-让系统管理员将LIBDIR添加到"/etc/ld.so.conf">

好的,继续:

(python)$ export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
(python)$ export CXXFLAGS=-I$HOME/usr/include
(python)$ export LDFLAGS=-L$HOME/usr/lib
(python)$ cd python
(python)$ python setup.py build

退出时显示:

Using EXPERIMENTAL C++ Implmenetation.
running build
running build_py
running build_ext
building 'google.protobuf.internal._net_proto2___python' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I. -I/opt/python-2.7/include/python2.7 -c google/protobuf/pyext/python_descriptor.cc -o build/temp.linux-x86_64-2.7/google/protobuf/pyext/python_descriptor.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
In file included from google/protobuf/pyext/python_descriptor.cc:36:
./google/protobuf/pyext/python_descriptor.h:39:40: error: google/protobuf/descriptor.h: No such file or directory
google/protobuf/pyext/python_descriptor.cc:37:43: error: google/protobuf/descriptor.pb.h: No such file or directory
In file included from google/protobuf/pyext/python_descriptor.cc:36:
./google/protobuf/pyext/python_descriptor.h:55: error: ISO C++ forbids declaration of ‘FieldDescriptor’ with no type
./google/protobuf/pyext/python_descriptor.h:55: error: invalid use of ‘::’
./google/protobuf/pyext/python_descriptor.h:55: error: expected ‘;’ before ‘*’ token
./google/protobuf/pyext/python_descriptor.h:81: error: expected constructor, destructor, or type conversion before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:48: error: expected initializer before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:93: warning: deprecated conversion from string constant to ‘char*’
google/protobuf/pyext/python_descriptor.cc:93: warning: deprecated conversion from string constant to ‘char*’
google/protobuf/pyext/python_descriptor.cc:93: warning: deprecated conversion from string constant to ‘char*’
google/protobuf/pyext/python_descriptor.cc:93: warning: deprecated conversion from string constant to ‘char*’
google/protobuf/pyext/python_descriptor.cc:93: warning: deprecated conversion from string constant to ‘char*’
google/protobuf/pyext/python_descriptor.cc:152: error: ISO C++ forbids declaration of ‘DescriptorPool’ with no type
google/protobuf/pyext/python_descriptor.cc:152: error: invalid use of ‘::’
google/protobuf/pyext/python_descriptor.cc:152: error: expected ‘;’ before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:158: error: expected unqualified-id before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:158: error: expected ‘)’ before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:158: error: expected initializer before ‘*’ token
google/protobuf/pyext/python_descriptor.cc:337: error: expected ‘}’ at end of input
google/protobuf/pyext/python_descriptor.cc:337: error: expected ‘}’ at end of input
google/protobuf/pyext/python_descriptor.cc:337: error: expected ‘}’ at end of input
google/protobuf/pyext/python_descriptor.cc:155: warning: ‘void google::protobuf::python::CDescriptorPoolDealloc(google::protobuf::python::CDescriptorPool*)’ declared ‘static’ but never defined
error: command 'gcc' failed with exit status 1

setuptools似乎没有注意到CXXFLAGS环境变量——您可以看到CXXFLAGS没有出现在gcc命令行中。考虑到它使用的是gcc而不是g++,它甚至可能没有意识到它正在编译C++。请尝试使用CFLAGS