我注意到还有一些人有问题,我看到的唯一解决方案是CXXFLAGSLDFLAGS,但这些似乎不起作用。
试图编译C++ PythBuffi以替代Python版本i,用VielalEnv和用户帐户在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 theld_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命令行中。看起来它甚至没有意识到它正在编译C++,考虑到它使用的是gcc而不是g++。尝试改用CFLAGS

关于python - protobuf python找不到包含,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23580506/

10-12 18:27