牧羊少年123 2016-06-01 07:28 采纳率: 0%
浏览 3603

C++在windows平台下利用thrift通信

在windows下使用C++和Thrift开发客户端程序与HBase进行通信,总是实现不了。
已经安装了thrift所依赖的boost,libevent,openssl底层东西,也成功编译出了libthrift.lib和libthriftnb.lib两个lib库。
客户端程序添加引用如下:
1.在C++/常规/附加包含目录中添加对头文件的引用:C:\openssl\include;C:\libevent\include;C:\boost\include;E:\HBase\thrift-0.9.3\lib\cpp\src;E:\HBase\thrift-0.9.3\lib\cpp\src\thrift。
2.在链接器/常规/附加库目录中添加库文件目录:C:\openssl\out32dll;C:\libevent\libs;C:\boost\libs;E:\HBase\thrift-0.9.3\lib\cpp\Debug
3.在链接器/输入/附加依赖项中添加对libthrift.lib和libthriftnb.lib两个lib库的引用

但是在创建客户端引用的过程中总是报错:

错误 2 error LNK2019: 无法解析的外部符号 "public: void __thiscall apache::thrift::TOutput::perror(char const *,int)" (?perror@TOutput@thrift@apache@@QAEXPBDH@Z),该符号在函数 "protected: void __thiscall apache::thrift::transport::TSocket::openConnection(struct addrinfo *)" (?openConnection@TSocket@transport@thrift@apache@@IAEXPAUaddrinfo@@@Z) 中被引用 E:\HBase\thrift-0.9.3\lib\cpp\CppDemo\libthrift.lib(TSocket.obj) CppDemo

错误 3 error LNK2019: 无法解析的外部符号 "public: static class std::basic_string,class std::allocator > __cdecl apache::thrift::TOutput::strerror_s(int)" (?strerror_s@TOutput@thrift@apache@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z),该符号在函数 "public: __thiscall apache::thrift::transport::TTransportException::TTransportException(enum apache::thrift::transport::TTransportException::TTransportExceptionType,class std::basic_string,class std::allocator > const &,int)" (??0TTransportException@transport@thrift@apache@@QAE@W4TTransportExceptionType@0123@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) 中被引用 E:\HBase\thrift-0.9.3\lib\cpp\CppDemo\libthrift.lib(TSocket.obj) CppDemo

程序代码如下:
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;

int _tmain(int argc, _TCHAR* argv[])
{
boost::shared_ptr socket(new TSocket("127.0.0.1", 9090));
return 0;
}

各位大神,可有办法?急...

  • 写回答

3条回答

  • 小灸舞 2016-06-01 08:04
    关注

    报错的perror和strerror_s都是在Thrift.h里的

    00001 /*
    00002  * Licensed to the Apache Software Foundation (ASF) under one
    00003  * or more contributor license agreements. See the NOTICE file
    00004  * distributed with this work for additional information
    00005  * regarding copyright ownership. The ASF licenses this file
    00006  * to you under the Apache License, Version 2.0 (the
    00007  * "License"); you may not use this file except in compliance
    00008  * with the License. You may obtain a copy of the License at
    00009  *
    00010  *   http://www.apache.org/licenses/LICENSE-2.0
    00011  *
    00012  * Unless required by applicable law or agreed to in writing,
    00013  * software distributed under the License is distributed on an
    00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    00015  * KIND, either express or implied. See the License for the
    00016  * specific language governing permissions and limitations
    00017  * under the License.
    00018  */
    00019 
    00020 #ifndef _THRIFT_THRIFT_H_
    00021 #define _THRIFT_THRIFT_H_ 1
    00022 
    00023 #ifdef HAVE_CONFIG_H
    00024 #include "config.h"
    00025 #endif
    00026 #include <stdio.h>
    00027 
    00028 #include <sys/types.h>
    00029 #include <netinet/in.h>
    00030 #ifdef HAVE_INTTYPES_H
    00031 #include <inttypes.h>
    00032 #endif
    00033 #include <string>
    00034 #include <map>
    00035 #include <list>
    00036 #include <set>
    00037 #include <vector>
    00038 #include <exception>
    00039 
    00040 #include "TLogging.h"
    00041 
    00042 namespace apache { namespace thrift {
    00043 
    00044 class TOutput {
    00045  public:
    00046   TOutput() : f_(&errorTimeWrapper) {}
    00047 
    00048   inline void setOutputFunction(void (*function)(const char *)){
    00049     f_ = function;
    00050   }
    00051 
    00052   inline void operator()(const char *message){
    00053     f_(message);
    00054   }
    00055 
    00056   // It is important to have a const char* overload here instead of
    00057   // just the string version, otherwise errno could be corrupted
    00058   // if there is some problem allocating memory when constructing
    00059   // the string.
    00060   void perror(const char *message, int errno_copy);
    00061   inline void perror(const std::string &message, int errno_copy) {
    00062     perror(message.c_str(), errno_copy);
    00063   }
    00064 
    00065   void printf(const char *message, ...);
    00066 
    00067   inline static void errorTimeWrapper(const char* msg) {
    00068     time_t now;
    00069     char dbgtime[26];
    00070     time(&now);
    00071     ctime_r(&now, dbgtime);
    00072     dbgtime[24] = 0;
    00073     fprintf(stderr, "Thrift: %s %s\n", dbgtime, msg);
    00074   }
    00075 
    00077   static std::string strerror_s(int errno_copy);
    00078 
    00079  private:
    00080   void (*f_)(const char *);
    00081 };
    00082 
    00083 extern TOutput GlobalOutput;
    00084 
    00085 class TException : public std::exception {
    00086  public:
    00087   TException() {}
    00088 
    00089   TException(const std::string& message) :
    00090     message_(message) {}
    00091 
    00092   virtual ~TException() throw() {}
    00093 
    00094   virtual const char* what() const throw() {
    00095     if (message_.empty()) {
    00096       return "Default TException.";
    00097     } else {
    00098       return message_.c_str();
    00099     }
    00100   }
    00101 
    00102  protected:
    00103   std::string message_;
    00104 
    00105 };
    00106 
    00107 
    00108 // Forward declare this structure used by TDenseProtocol
    00109 namespace reflection { namespace local {
    00110 struct TypeSpec;
    00111 }}
    00112 
    00113 
    00114 }} // apache::thrift
    00115 
    00116 #endif // #ifndef _THRIFT_THRIFT_H_
    Generated on Tue Jan 24 2012 16:03:28 for TDAQ release tdaq-04-00-01 by   doxygen 1.7.2
    
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题