由於C++的特殊性,我們建議您先用本文介紹的方法編譯,複製build/release/src/tablestore/core/impl/buildinfo.cpp
備用。然後將C++ SDK源碼以及buildinfo.cpp
複製到您自己的程式碼程式庫中,並用您的編譯系統來進行編譯。
編譯參數
在編譯用戶端代碼的時候,有些編譯器的行為是必須保證的,即,某些編譯器參數是必須的。
以下是針對gcc編譯器的編譯參數及說明。
參數 | 是否必須 | 說明 |
---|---|---|
--std=gnu++03 | 必須 | 支援C++98 TR1語言版本,帶gcc擴充(即typeof)。 |
-pthread | 必須 | 多線程編程的必要參數。編譯或者連結都需要加上該參數。 |
-fwrapv | 必須 | 整型資料溢出則迴轉,即,無符號整型向上溢出則成為0,有符號整型向上溢出則成為最小的負數。用戶端基於這個行為做溢出檢查。 |
-O2 | 建議存在 | 最佳化層級。一般不建議更高的最佳化層級。 |
-fsanitize=address和-fvar-tracking-assignments | 建議存在 | gcc-4.9之後支援libasan,可以快速而輕量地檢測各種記憶體使用量上的錯誤。如果需要Table Store的開發人員定位錯誤,請帶上這兩個編譯參數複現錯誤,並且在連結的時候也需要帶上前一個參數。
注意 libasan和valgrind不相容。
|
環境依賴與先行編譯包
本文以debian8系統為例說明產生先行編譯包的方法。
- 開啟
docker/debian8/Dockerfile
檔案,選擇dockerfile的方式輸出用戶端對系統的環境依賴。這種方式可以自動保證代碼和環境的一致性。RUN apt-get install -y scons g++ libboost-all-dev protobuf-compiler libprotobuf-dev uuid-dev libssl-dev RUN apt-get install -y ca-certificates # for HTTPS support
SDK依賴以下幾項:
- scons & gcc: 編譯系統
- boost
- uuid
- protobuf:序列化庫
- openssl:簽名,以及支援HTTPS所用
- ca-certificates:僅為支援HTTPS所用。如果您只用Table Store的HTTP地址,可以不安裝這個庫。建議使用更為安全的HTTPS。
- 安裝以上包之後便可以編譯用戶端。方法是下載用戶端的源碼,並在源碼目錄下執行
scons
。$ git clone https://github.com/aliyun/aliyun-tablestore-cpp-sdk.git $ cd aliyun-tablestore-cpp-sdk $ scons -j4
當上述步驟正常結束,一個tar包就編譯好了。包名通常可以在scons
最後的輸出中找到。例如debian8系統,包名及所在的路徑是:build/release/pkg/aliyun-tablestore-cpp98-sdk-4.4.1-debian8.9-x86_64.tar.gz
。
-
包名裡包含以下幾個要素:
- C++版本(C++98)
- SDK版本(4.4.1)
- OS版本(debian8.9)
- OS架構(x86_64)
-
包的內容包括:
$ tar -tf build/release/pkg/aliyun-tablestore-cpp98-sdk-4.4.1-debian8.9-x86_64.tar.gz version.ini lib/libtablestore_core.so lib/libtablestore_core_static.a lib/libtablestore_util.so lib/libtablestore_util_static.a include/tablestore/util/arithmetic.hpp include/tablestore/util/assert.hpp include/tablestore/util/foreach.hpp include/tablestore/util/iterator.hpp include/tablestore/util/logger.hpp include/tablestore/util/logging.hpp include/tablestore/util/mempiece.hpp include/tablestore/util/mempool.hpp include/tablestore/util/metaprogramming.hpp include/tablestore/util/move.hpp include/tablestore/util/optional.hpp include/tablestore/util/prettyprint.hpp include/tablestore/util/random.hpp include/tablestore/util/result.hpp include/tablestore/util/security.hpp include/tablestore/util/seq_gen.hpp include/tablestore/util/threading.hpp include/tablestore/util/timestamp.hpp include/tablestore/util/try.hpp include/tablestore/util/assert.ipp include/tablestore/util/iterator.ipp include/tablestore/util/logging.ipp include/tablestore/util/mempiece.ipp include/tablestore/util/move.ipp include/tablestore/util/prettyprint.ipp include/tablestore/core/client.hpp include/tablestore/core/error.hpp include/tablestore/core/range_iterator.hpp include/tablestore/core/retry.hpp include/tablestore/core/types.hpp
即,包內容包含以下元素:
- 版本檔案:
version.ini
- 庫檔案:
lib/
下所有檔案。其中libtablestore_core_static.a
依賴libtablestore_util_static.a
,動態庫也類似。 - 標頭檔:
include/
下所有檔案。
- 版本檔案: