节俭和提升-具有初始化但类型不完整

时间:2018-06-26 18:11:57

标签: c++ boost thrift

我目前正在使用节俭的示例:Click

我创建的以下测试代码无法编译。

#include <thrift/transport/TSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TBinaryProtocol.h>

using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;

int main(int argc, char **argv) {
    boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
    boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
    boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

    return 0;
}

尝试编译时,会发生以下异常:

/opt/JetBrains/apps/CLion/ch-0/181.5087.36/bin/cmake/bin/cmake --build /home/user/Documents/Projects/VerteilteSysteme/Insurer/cmake-build-debug --target Insurer -- -j 2
Scanning dependencies of target Insurer
[ 50%] Building CXX object CMakeFiles/Insurer.dir/main.cpp.o
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp: In function ‘int main(int, char**)’:
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:10:38: error: variable ‘boost::shared_ptr<apache::thrift::transport::TSocket> socket’ has initializer but incomplete type
     boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
                                      ^
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:11:44: error: variable ‘boost::shared_ptr<apache::thrift::transport::TTransport> transport’ has initializer but incomplete type
     boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
                                            ^
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:12:42: error: variable ‘boost::shared_ptr<apache::thrift::protocol::TProtocol> protocol’ has initializer but incomplete type
     boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
                                          ^
make[3]: *** [CMakeFiles/Insurer.dir/build.make:63: CMakeFiles/Insurer.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/Insurer.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/Insurer.dir/rule] Error 2
make: *** [Makefile:118: Insurer] Error 2

我仔细检查了一下,boost和thrift是否已正确安装在我的系统上。 (ArchLinux x64)。是什么原因导致此错误?

1 个答案:

答案 0 :(得分:2)

#include <boost/shared_ptr.hpp>

也许是在Thrift的标头中的某个位置预先声明的?