protobuf python找不到包含
Posted
技术标签:
【中文标题】protobuf python找不到包含【英文标题】:protobuf python can't find include 【发布时间】:2014-05-10 11:31:10 【问题描述】:我注意到其他一些问题,我看到的唯一解决方案包括 CXXFLAGS
和 LDFLAGS
,但这些似乎不起作用。
尝试为我在 CentOS 上使用 virtualenv 和用户帐户编译和安装的替代 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' 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
【问题讨论】:
google/protobuf/descriptor.h
在哪里?
(python)$ cd ~/;查找 ./ -iname descriptor.h ./usr/include/google/protobuf/descriptor.h ./src/protobuf-2.5.0/src/google/protobuf/descriptor.h (python)$
setuptools 似乎没有注意CXXFLAGS
环境变量——您可以看到您的CXXFLAGS
没有出现在gcc 命令行中。考虑到它使用的是gcc
而不是g++
,它看起来甚至可能不知道它正在编译C++。 CFLAGS
有效吗?
谢谢 Kenton,这似乎可行,虽然我仍然无法让测试('python setup.py test')工作,但至少安装似乎工作;并且通过一两个示例,这似乎也有效。您会将此作为答案,以便我可以将其标记为已接受的答案,以便您获得适当的信用吗?
【参考方案1】:
setuptools 似乎没有注意CXXFLAGS
环境变量——您可以看到CXXFLAGS
没有出现在gcc
命令行中。考虑到它使用的是gcc
而不是g++
,它看起来甚至可能不知道它正在编译C++。尝试改用CFLAGS
。
【讨论】:
我在这个话题上唯一悬而未决的问题是为什么“python setup.py test”失败了。除此之外,您的解决方案似乎有效,谢谢。 @PinBot 没有日志很难说。可能是因为PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
——它开启了一个实验性的实现,它有一些模糊的问题。以上是关于protobuf python找不到包含的主要内容,如果未能解决你的问题,请参考以下文章
致命错误:找不到“google/protobuf/compiler/plugin.h”文件
在 docker 容器中安装 CMake 时出错。找不到 PROTOBUF
pod spec lint 错误:无法构建模块“Protobuf”,找不到文件:#import "google/protobuf/Any.pbobjc.h"
Go语言 go get 找不到 google.golang.org/protobuf/encoding/prototext 解决办法