2012-01-06 12 views
2

私は、スリフトインタフェースを使用してcassandraインスタンスに接続するための簡単な例をコンパイルしようとしていました。メモとして、私はLinuxマシン上でスーパーユーザー特権にアクセスすることなく、これをすべて実行しています。thriftとcassandraを使用したC++プログラムのコンパイル

私はthriftとC++ジェネレータをインストールし、インクルードヘッダーをCPLUS_INCLUDE_PATH変数に、libディレクトリをLIBRARY_PATHとLD_LIBRARY_PATHに配置しました。 Cassandraもインストールされており、私はthrift --gen cpp cassandra.thriftを実行してcassandraヘッダーファイルを生成しました。これらのIを使用して

はそう
g++ -Wall run_measure.cpp cassandra_constants.cpp Cassandra.cpp cassandra_types.cpp -lthrift -o cassandra_example

プログラムは主にこの

#include "Cassandra.h" 

#include <protocol/TBinaryProtocol.h> 
#include <transport/TSocket.h> 
#include <transport/TTransportUtils.h> 

using namespace std; 
using namespace apache::thrift; 
using namespace apache::thrift::protocol; 
using namespace apache::thrift::transport; 
using namespace org::apache::cassandra; 
using namespace boost; 

int main(int argc, const char* argv[]) { 
    shared_ptr socket(new TSocket(host, port)); 
    shared_ptr transport(new TFramedTransport(socket)); 
    shared_ptr protocol(new TBinaryProtocol(transport)); 
    CassandraClient client(protocol); 

    const string& key="your_key"; 

    ColumnPath cpath; 
    ColumnParent cp; 

    ColumnOrSuperColumn csc; 
    Column c; 

    c.name.assign("column_name"); 
    c.value.assign("Data for our key to go into column_name"); 
    c.timestamp = getTS(); 
    c.ttl = 300; 

    cp.column_family.assign("nm_cfamily"); 
    cp.super_column.assign(""); 

    cpath.column_family.assign("nm_cfamily"); 
    /* This is required - thrift 'feature' */ 
    cpath.__isset.column = true; 
    cpath.column="column_name"; 
    try { 
      transport->open(); 
      cout << "Set keyspace to 'dpdns'.." << endl; 
      client.set_keyspace("nm_example"); 

      cout << "Insert key '" << key << "' in column '" << c.name << "' in column family '" << cp.column_family << "' with timestamp " << c.timestamp << "..." << endl; 
      client.insert(key, cp, c, org::apache::cassandra::ConsistencyLevel::ONE); 

      cout << "Retrieve key '" << key << "' from column '" << cpath.column << "' in column family '" << cpath.column_family << "' again..." << endl; 
      client.get(csc, key, cpath, org::apache::cassandra::ConsistencyLevel::ONE); 
      cout << "Value read is '" << csc.column.value << "'..." << endl; 

      c.timestamp++; 
      c.value.assign("Updated data going into column_name"); 
      cout << "Update key '" << key << "' in column with timestamp " << c.timestamp << "..." << endl; 
      client.insert(key, cp, c, org::apache::cassandra::ConsistencyLevel::ONE); 

      cout << "Retrieve updated key '" << key << "' from column '" << cpath.column << "' in column family '" << cpath.column_family << "' again..." << endl; 
      client.get(csc, key, cpath, org::apache::cassandra::ConsistencyLevel::ONE); 
      cout << "Updated value is: '" << csc.column.value << "'" << endl; 

      cout << "Remove the key '" << key << "' we just retrieved. Value '" << csc.column.value << "' timestamp " << csc.column.timestamp << " ..." << endl; 
    client.remove(key, cpath, csc.column.timestamp, org::apache::cassandra::ConsistencyLevel::ONE); 

    transport->close(); 
} 
catch (NotFoundException &nf){ 
cerr << "NotFoundException ERROR: "<< nf.what() << endl; 
} 
catch (InvalidRequestException &re) { 
cerr << "InvalidRequest ERROR: " << re.why << endl; 
} 
catch (TException &tx) { 
cerr << "TException ERROR: " << tx.what() << endl; 
} 

return 0; 
} 

のように見える私が手にエラーが事についてほとんど文句

In file included from run_measure.cpp:13: 
Cassandra.h:4289: error: ‘org::apache::thrift’ has not been declared 
Cassandra.h:4289: error: expected ‘,’ or ‘...’ before ‘*’ token 
Cassandra.h:4291: error: cannot declare pointer to ‘void’ member 
Cassandra.h:4291: error: template argument 2 is invalid 
Cassandra.h:4291: error: template argument 4 is invalid 
Cassandra.h:4292: error: ‘org::apache::thrift’ has not been declared 
Cassandra.h:4292: error: expected ‘,’ or ‘...’ before ‘*’ token 
Cassandra.h:4293: error: ‘org::apache::thrift’ has not been declared 
Cassandra.h:4293: error: expected ‘,’ or ‘...’ before ‘*’ token 
Cassandra.h:4294: error: ‘org::apache::thrift’ has not been declared 
Cassandra.h:4294: error: expected ‘,’ or ‘...’ before ‘*’ token 
Cassandra.h:4295: error: ‘org::apache::thrift’ has not been declared 
Cassandra.h:4295: error: expected ‘,’ or ‘...’ before ‘*’ token 

そのあるように私の例をコンパイル生成されたファイルでは、私はそれらを変更することができるかどうか、または私が何か他の何かを間違ったかどうかはわかりません。参考のため、私の倹約のインストールは$HOME/thriftになっていますので、インクルードのパスがちょっと変わってしまいました。$HOME/thrift/include/thriftのように見えますが、このエラーが発生するとは思われません。 C + +でcassandraを使った経験がある人は、本当に助けていただければ幸いです。

はここ

while (true) 
    { 
    xfer += iprot->readFieldBegin(fname, ftype, fid); 
    if (ftype == ::apache::thrift::protocol::T_STOP) { 
     break; 
    } 
    switch (fid) 
    { 
     default: 
     xfer += iprot->skip(ftype); 
     break; 
    } 
    xfer += iprot->readFieldEnd(); 
    } 

    xfer += iprot->readStructEnd(); 

    return xfer; 
} 

Full Cassandra.cpp
Full Error

おかげで再びエラーで参照線です!

+0

「Cassandra.h」から完全なエラーと多分4289行を投稿できますか?私は生成されたファイルがパス設定で '#include 'を使用している間に '#include 'を試みると思う。 –

+0

フルファイルへのリンクが含まれています – RedbeardTheNinja

+0

変数CPLUS_INCLUDE_PATH、LD_LIBRARY_PATH、およびLIBRARY_PATHにどのような変数が含まれているか表示できますか?私の疑念は、彼らはリサイクルの種類の開始が含まれている適切な "トップレベル"を参照していないということです。 – Dave

答えて

2

私は同じ問題を抱えていて、修正しました。
gccの場合は、Cassandra.h、Cassandra.cppに変更を加える必要があります。あなたはすべてのapache -> ::apacheは倹約-0.8発電機に、このパッチを適用交換したくない場合は>::apache::thrift

+0

これは古本の版からの変更であるように思われるが、それはcassandra 1が判明した。0は倹約0.6を使用し、私は最新のバージョンを使用していました。 – RedbeardTheNinja

1

ピエールのパッチには1つの修正がないと思う。私はマイナーチェンジしました。それはavailable on pastebinです。

私は間違っているかもしれません。もし私が訂正してくれれば、これは私がパッチでプレイした初めてのことです。

関連する問題