modify date:2018.03.22
[TOC]
To use the AWS SDK for C++, you need:
Visual Studio 2013 or later
? Note:Visual Studio 2013 doesn't provide default move constructors and operators. Later versions of Visual Studio provide a standards-compliant compiler.
or GNU Compiler Collection (GCC) 4.9 or later
or Clang 3.3 or later
A minimum of 4 GB of RAM
(
-dev
packages) forlibcurl
,libopenssl
,libuuid
,zlib
cmake
version > 3.0
unix 編譯依賴
libz
curl
openssl
libuuid
Ubuntu 安裝開發(fā)庫 sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libpulse-dev
openssluuidzlibcurl
安裝新版本 gcc 和 gdb
# 1. Install a package with repository for your system:# On CentOS, install package centos-release-scl available in CentOS repository:$ sudo yum install centos-release-scl# On RHEL, enable RHSCL repository for you system:$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms# 2. Install the collection:$ sudo yum install devtoolset-7# 3. Start using software collections:$ scl enable devtoolset-7 bash
安裝 cmake
yum install llvm-toolset-7
ccmake-命令行界面,交互模式。
安裝 libz,curl,openssl 和 libuuid 的 devel 版
通過 cmake 配置生成模塊,cmake /mnt/hd03.d/xdu.d/aws/source/aws-sdk-cpp -DBUILD_ONLY="s3"
-DCMAKE_BUILD_TYPE=Release
cmake /mnt/hd03.d/xdu.d/aws/source/aws-sdk-cpp -DBUILD_ONLY="core;s3;transfer" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_BUILD_TYPE=Release
動態(tài)庫
cmake /mnt/hd03.d/xdu.d/aws/source/aws-sdk-cpp -DBUILD_ONLY="core;s3;transfer" -DBUILD_SHARED_LIBS="ON" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC
動態(tài)鏈接需要定義 USE_IMPORT_EXPORT
If you dynamically link to the SDK you will need to define the USE_IMPORT_EXPORT symbol for all build targets using the SDK
GCC: what are the --start-group and --end-group command line options?
It is for resolving circular dependences between several libraries
Impossible to link static libraries with circular dependencies
在 aws 的靜態(tài)庫中,有循環(huán)引用問題。
In a project we have multiple static libraries (build using cdt), two of which have circular dependencies to each other, that link together into an executable (also built using cdt).
With the "GCC C Linker" selected it's impossible to build that file. The linker complains about missing references when the static libraries are simply added in the "C/(C++ Build -> Settings -> GCC C Linker -> Libraries" tab, because references of the library that appears last on the generated command line has undefined references.
The solution would be to add "--start-group -lX -lY --end-group" to the linker command line after the list of the object files. But that's simply not possible. The additional linker options (both the "Linker flags" and "Other options (-Xlinker [option])" fields) that can be specified on the "GCC C Linker -> Miscellaneous" tab are added to the command line before the object, which has essentially no effect.
N.B. In our project I have installed a (dirty) workaround: I have added the linker options (-Wl,--start-group,-lX,-lY,--end-group) to the "Other objects" field (and added a dummy make rule in makefile.init so make won't complain about it) to force CDT to put it after the list of objects. It works but is really ugly.
使用 GCC 可將鏈接參數(shù)傳遞給鏈接器使用 -Wl,--start-group
和 -Wl,--end-group
-Wl,--start-group -laws-cpp-sdk-core -laws-cpp-sdk-s3 -laws-cpp-sdk-transfer-Wl,--end-group
//linux makefileCC = g++CCFLAGS = -DNDEBUG -std=c++11 -O0INCLUDE := -I../LDFLAGS := -L../aws/bin/linux/static -Wl,-rpath ./ -Wl,-rpath ../aws/bin/linux/dynamicLIBS := -lcurl -pthread -lcrypto -Wl,--start-group -laws-cpp-sdk-core -laws-cpp-sdk-s3 -laws-cpp-sdk-transfer -Wl,--end-groupmake: main rm *.o @echo successmain: $(CC) $(CCFLAGS) $(INCLUDE) -c -o main.o main.cpp $(CC) $(CCFLAGS) $(INCLUDE) $(LDFLAGS) -o transfer main.o $(LIBS)
Mac 下不需要 -pthread -lcrypto
readelf -d libbar.so
$ readelf -d ../aws/bin/linux/dynamic/libaws-cpp-sdk-transfer.soDynamic section at offset 0x29c38 contains 36 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libaws-cpp-sdk-s3.so] 0x0000000000000001 (NEEDED) Shared library: [libaws-cpp-sdk-core.so] 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0] 0x0000000000000001 (NEEDED) Shared library: [libcurl.so.4] 0x0000000000000001 (NEEDED) Shared library: [libssl.so.10] 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.10] 0x0000000000000001 (NEEDED) Shared library: [libz.so.1] 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6] 0x0000000000000001 (NEEDED) Shared library: [libm.so.6] 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000e (SONAME) Library soname: [libaws-cpp-sdk-transfer.so]
gcc -shared -o libmerge.so -Wl,--whole-archive libaws-cpp-sdk-core.a libaws-cpp-sdk-s3.a libaws-cpp-sdk-transfer.a -Wl,--no-whole-archive
使用 cmake 生成工程,到生成庫目錄下,此處打開PowerShell
然后運行指令
& "E:\Software Install\cmake-3.11.0-rc3-win64-x64\cmake-3.11.0-rc3-win64-x64\bin\cmake" E:\libs\aws-sdk-cpp-1.4.11 -DBUILD_ONLY="transfer" -DBUILD_SHARED_LIBS=ON -DSTATIC_LINKING=1 -DTARGET=WINDOWS -G "Visual Studio 15 2017"
windows 靜態(tài)鏈接 aws static lib 需要依賴于幾個系統(tǒng)靜態(tài)庫
winhttp.lib wininet.lib bcrypt.lib userenv.lib Version.lib
靜態(tài)鏈接出現(xiàn) GetObjectA/GetObjectW 錯誤,由于 wingdi.h
中定義了
//wingdi.h#ifdef UNICODE#define GetObject GetObjectW#else#define GetObject GetObjectA#endif // !UNICODE
在 S3Client.h
被包含之前取消 GetObject 定義
//on windows visual studio//undef GetObject to avoid marco conflict#if defined _WIN32 && defined GetObject#undef GetObject#endif
聯(lián)系客服