tutorial 最簡單例子
1.安裝成功後進入 tutorial 目錄 運行 thrift -r --gen cpp tutorial.thrift 會在gen-cpp目錄下生成一些文件
2. 進入 cpp 目錄 ,然後直接進行 make
3. 編譯成功的會生成 CppClient 和 CppServer
other...
- 新建 test.thrift 文件,內容如下
- 運行 thrift --gen cpp test.thrift 進行生成c++格式的代碼,可以在當前 代碼會生成在 gen-cpp 目錄
- 進入 gen-cpp 目錄,複製一份 cp Something_server.skeleton.cpp Something_server.cp
- 添加一些環境變量,用於指定編譯時的庫文件路徑,運行
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:/usr/lib/
可以把該命令加到 ~/.bashrc 文件裏,以便每次登錄自動運行 - 快速編譯 g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something
在編譯時如提示存在多個 main() ,按提示註釋掉 Something_server.skeleton.cpp 裏的 main() 代碼 - 如果要進行手工編譯如下:
- 運行 編譯後生成的 ./something
參考
ThriftUsageC++
http://wiki.apache.org/thrift/ThriftUsageC%2B%2B
error while loading shared libraries
http://hi.baidu.com/%C6%AE%BA%F6%B5%C4%C3%E6%B0%FC%CA%F7/blog/item/72daf0508b05271f367abe83.html