protobuf python 找不到包含文件
我注意到有些人遇到了问题,而我看到的唯一解决办法涉及到 CXXFLAGS
和 LDFLAGS
,但这些似乎并没有奏效。
我在CentOS上使用虚拟环境和用户账户,尝试为我安装的另一个Python版本编译C++的protobuff:
$ 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
这个标志,并至少执行以下操作之一: - 在执行时将LIBDIR添加到LD_LIBRARY_PATH
环境变量中 - 在链接时将LIBDIR添加到LD_RUN_PATH
环境变量中 - 使用-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
1 个回答
0
看起来 setuptools 并没有注意到 CXXFLAGS
这个环境变量——你可以看到你的 CXXFLAGS
并没有出现在 gcc
的命令行中。它似乎甚至不知道自己在编译 C++,因为它用的是 gcc
而不是 g++
。试试用 CFLAGS
来代替。