質問編集履歴
7
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -457,3 +457,107 @@
|
|
457
457
|
|
458
458
|
|
459
459
|
Thriftのクライアント側のビルドが成功したのでサーバ側のソースを同じ環境でビルドしたのですが、そちら側は失敗してしまいました。
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
サーバ側のソースコードはこちらです
|
466
|
+
|
467
|
+
```cpp
|
468
|
+
|
469
|
+
#include <TinyCalc.h>
|
470
|
+
|
471
|
+
#include <thrift/protocol/TBinaryProtocol.h>
|
472
|
+
|
473
|
+
#include <thrift/server/TSimpleServer.h>
|
474
|
+
|
475
|
+
#include <thrift/transport/TServerSocket.h>
|
476
|
+
|
477
|
+
#include <thrift/transport/TBufferTransports.h>
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
using namespace ::apache::thrift;
|
482
|
+
|
483
|
+
using namespace ::apache::thrift::protocol;
|
484
|
+
|
485
|
+
using namespace ::apache::thrift::transport;
|
486
|
+
|
487
|
+
using namespace ::apache::thrift::server;
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
using boost::shared_ptr;
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
class TinyCalcHandler : virtual public TinyCalcIf {
|
496
|
+
|
497
|
+
public:
|
498
|
+
|
499
|
+
TinyCalcHandler() {
|
500
|
+
|
501
|
+
// Your initialization goes here
|
502
|
+
|
503
|
+
}
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
double sum(const double param1, const double param2) {
|
508
|
+
|
509
|
+
// Your implementation goes here
|
510
|
+
|
511
|
+
printf("sum\n");
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
return param1 + param2;
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
double subtract(const double param1, const double param2) {
|
522
|
+
|
523
|
+
// Your implementation goes here
|
524
|
+
|
525
|
+
printf("subtract\n");
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
return param1 - param2;
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
};
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
int main(int argc, char **argv) {
|
540
|
+
|
541
|
+
int port = 9090;
|
542
|
+
|
543
|
+
shared_ptr<TinyCalcHandler> handler(new TinyCalcHandler());
|
544
|
+
|
545
|
+
shared_ptr<TProcessor> processor(new TinyCalcProcessor(handler));
|
546
|
+
|
547
|
+
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
|
548
|
+
|
549
|
+
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
|
550
|
+
|
551
|
+
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
|
556
|
+
|
557
|
+
server.serve();
|
558
|
+
|
559
|
+
return 0;
|
560
|
+
|
561
|
+
}
|
562
|
+
|
563
|
+
```
|
6
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -313,3 +313,147 @@
|
|
313
313
|
|
314
314
|
|
315
315
|
これらのソースは[github](https://github.com/okanon/thrift_cpp)にアップロードしてあります
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
## 2017 11/2 15:14 追記
|
326
|
+
|
327
|
+
使用するThriftを[Thrift0.9.3](http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.3/thrift-0.9.3.tar.gz)ではなく最新の[Thrift0.10.0](http://www.apache.org/dyn/closer.cgi?path=/thrift/0.10.0/thrift-0.10.0.tar.gz)に変えて、**TProtocol.cpp**をプロジェクトに追加
|
328
|
+
|
329
|
+
そのlibを対象のプロジェクトで参照したところ、Thriftのみのソースではビルドができました。↓
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
```cpp
|
334
|
+
|
335
|
+
#include <thrift/protocol/TBinaryProtocol.h>
|
336
|
+
|
337
|
+
#include <thrift/transport/TSocket.h>
|
338
|
+
|
339
|
+
#include <thrift/transport/TTransportUtils.h>
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
using namespace std;
|
344
|
+
|
345
|
+
using namespace apache::thrift;
|
346
|
+
|
347
|
+
using namespace apache::thrift::transport;
|
348
|
+
|
349
|
+
using namespace apache::thrift::protocol;
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
using namespace boost;
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
int main() {
|
358
|
+
|
359
|
+
boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
return 0;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
```
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
**この時、Nugetからインストールされてるはずのboostが何故か参照されないエラーが発生したので、Nugetからでなく自分でビルドしたboostを使用したところ、エラーを吐かなくなりました。**
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
thriftでコンパイルしたTinyCalcをビルドしてみろという指摘があったのでスタティックライブラリとしてビルドした後、libthrift.libと同じように参照し以下のソースを書いてビルドしてみました
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
```cpp
|
380
|
+
|
381
|
+
#include <stdio.h>
|
382
|
+
|
383
|
+
#include <iostream>
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
#include <thrift/protocol/TBinaryProtocol.h>
|
388
|
+
|
389
|
+
#include <thrift/transport/TSocket.h>
|
390
|
+
|
391
|
+
#include <thrift/transport/TTransport.h>
|
392
|
+
|
393
|
+
#include <thrift/transport/TTransportUtils.h>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
#include <TinyCalc.h>
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
using namespace std;
|
402
|
+
|
403
|
+
using namespace apache::thrift;
|
404
|
+
|
405
|
+
using namespace apache::thrift::protocol;
|
406
|
+
|
407
|
+
using namespace apache::thrift::transport;
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
using namespace boost;
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
int main() {
|
416
|
+
|
417
|
+
boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
|
418
|
+
|
419
|
+
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
420
|
+
|
421
|
+
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
422
|
+
|
423
|
+
TinyCalcClient client(protocol);
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
try {
|
428
|
+
|
429
|
+
transport->open();
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
double sum = client.sum(1.0, 1.0);
|
434
|
+
|
435
|
+
std::cout << "1 + 1 = " << sum << std::endl;
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
transport->close();
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
catch (TException &tx) {
|
444
|
+
|
445
|
+
std::cout << "ERROR: " << &tx << std::endl;
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
```
|
452
|
+
|
453
|
+
すると、今度はSSLSocketでリンクエラーが発生しました。
|
454
|
+
|
455
|
+
このSSLSocketは使う機会がほとんどなく、別のものに依存しないので、**ThriftのプロジェクトからSSLSocketのみを外してビルド**し、そのlibを使って上記のコードをビルドしたところ、リンクエラーが発生することもなくビルドが成功しました。
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
Thriftのクライアント側のビルドが成功したのでサーバ側のソースを同じ環境でビルドしたのですが、そちら側は失敗してしまいました。
|
5
ミス修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -312,4 +312,4 @@
|
|
312
312
|
|
313
313
|
|
314
314
|
|
315
|
-
これらのソースは[github](
|
315
|
+
これらのソースは[github](https://github.com/okanon/thrift_cpp)にアップロードしてあります
|
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -307,3 +307,9 @@
|
|
307
307
|
エラー内容はこちらです。
|
308
308
|
|
309
309
|
![イメージ説明](a8996a8905e75d2aeac34608c7e9d992.png)
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
これらのソースは[github]()https://github.com/okanon/thrift_cppにアップロードしてあります
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -215,3 +215,95 @@
|
|
215
215
|
|
216
216
|
|
217
217
|
これらのコードはthriftで自動的に作成されるコードです。
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
TinyCalcの部分をコメントアウトしたものがこちらです
|
222
|
+
|
223
|
+
```cpp
|
224
|
+
|
225
|
+
#include <stdio.h>
|
226
|
+
|
227
|
+
#include <iostream>
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
#include <thrift/protocol/TBinaryProtocol.h>
|
232
|
+
|
233
|
+
#include <thrift/transport/TSocket.h>
|
234
|
+
|
235
|
+
#include <thrift/transport/TTransportUtils.h>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
//#include "../gen-cpp/TinyCalc.h"
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
using namespace std;
|
246
|
+
|
247
|
+
using namespace apache::thrift;
|
248
|
+
|
249
|
+
using namespace apache::thrift::transport;
|
250
|
+
|
251
|
+
using namespace apache::thrift::protocol;
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
using namespace boost;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
int main() {
|
260
|
+
|
261
|
+
boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
|
262
|
+
|
263
|
+
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
264
|
+
|
265
|
+
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
266
|
+
|
267
|
+
/*
|
268
|
+
|
269
|
+
TinyCalcClient client(protocol);
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
try {
|
274
|
+
|
275
|
+
transport->open();
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
double sum = client.sum(1.0, 1.0);
|
280
|
+
|
281
|
+
std::cout << "1 + 1 = " << sum << std::endl;
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
transport->close();
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
catch (TException &tx) {
|
290
|
+
|
291
|
+
std::cout << "ERROR: " << &tx << std::endl;
|
292
|
+
|
293
|
+
}*/
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
return 0;
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
thriftとboostしか使用していませんが、リンクエラーが出ます。
|
304
|
+
|
305
|
+
boostはNugetからインストール済みです。
|
306
|
+
|
307
|
+
エラー内容はこちらです。
|
308
|
+
|
309
|
+
![イメージ説明](a8996a8905e75d2aeac34608c7e9d992.png)
|
2
thriftファイルの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,73 @@
|
|
145
145
|
### 開発環境
|
146
146
|
|
147
147
|
Visual Studio 2017 Community
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
### 追記
|
152
|
+
|
153
|
+
gen-cpp内はこのようになっています。
|
154
|
+
|
155
|
+
![イメージ説明](7679e539d894de06689cfcbd284c9e3a.png)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```cpp
|
160
|
+
|
161
|
+
//TinyCalc.h
|
162
|
+
|
163
|
+
ifndef TinyCalc_H
|
164
|
+
|
165
|
+
#define TinyCalc_H
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
#include <thrift/TDispatchProcessor.h>
|
170
|
+
|
171
|
+
#include <thrift/async/TConcurrentClientSyncInfo.h>
|
172
|
+
|
173
|
+
#include "TinyCalc_types.h"
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
#ifdef _WIN32
|
182
|
+
|
183
|
+
#pragma warning( push )
|
184
|
+
|
185
|
+
#pragma warning (disable : 4250 ) //inheriting methods via dominance
|
186
|
+
|
187
|
+
#endif
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
class TinyCalcIf {
|
192
|
+
|
193
|
+
public:
|
194
|
+
|
195
|
+
virtual ~TinyCalcIf() {}
|
196
|
+
|
197
|
+
virtual double sum(const double param1, const double param2) = 0;
|
198
|
+
|
199
|
+
virtual double subtract(const double param1, const double param2) = 0;
|
200
|
+
|
201
|
+
};
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
....
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
TinyCalc_types.hは必要な値を入れていないので使われません
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
これらのコードはthriftで自動的に作成されるコードです。
|
1
画像と説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -108,6 +108,30 @@
|
|
108
108
|
|
109
109
|
libthrift.libとそのヘッダファイルは参照されている。
|
110
110
|
|
111
|
+
![イメージ説明](f1e2692a0618481725fa466bd308fa75.png)
|
112
|
+
|
113
|
+
**追加のインクルードディレクトリ**はヘッダファイルが置いてあるディレクトリを参照している
|
114
|
+
|
115
|
+
src以下はこのような感じにディレクトリがある
|
116
|
+
|
117
|
+
![イメージ説明](f998fe970bfbb458408b416c3a3eef37.png)
|
118
|
+
|
119
|
+
![イメージ説明](41b3b19775ac9943a1b71c0281ac052c.png)
|
120
|
+
|
121
|
+
![イメージ説明](6208f0bf527aa851ff504762df6d597f.png)
|
122
|
+
|
123
|
+
![イメージ説明](8a2c7e00bd9f9066a066ba66351c98d9.png)
|
124
|
+
|
125
|
+
Client.cppには特に赤波線のエラーは出ていない
|
126
|
+
|
127
|
+
libファイルはDebug/Releaseで分けてある
|
128
|
+
|
129
|
+
![イメージ説明](84932791478f19a979c46460aa108aaf.png)
|
130
|
+
|
131
|
+
上図のReleaseディレクトリの中身
|
132
|
+
|
133
|
+
![イメージ説明](36deed4d6b3607a0fa346583e4b4c3e2.png)
|
134
|
+
|
111
135
|
|
112
136
|
|
113
137
|
### エラー内容
|