Windows下基於MINGW編譯aliyun-oss-cpp-sdk
注意:以下編譯的都是64位版本的庫,如果需要編譯32位,需要將MINGW切換版本
安裝CMake工具
Cmake-3.18.0 rc1 :https://github.com/Kitware/CMake/releases/download/v3.18.0-rc2/cmake-3.18.0-rc2-win64-x64.msi
安裝MINGW工具
mingw-w64-v7.0.0:http://www.mingw-w64.org/doku.php/download
安裝類型:x86_64-8.1.0-posix-seh-rt_v6-rev0
設置系統環境變量:
下載aliyun-oss-cpp-sdk
https://github.com/aliyun/aliyun-oss-cpp-sdk
編譯
修改代碼:
src/utils/FileSystemUtils.cc
增加如下代碼:
std::string ws2s(const std::wstring &ws)
{
size_t i;
std::string curLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "chs");
const wchar_t* _source = ws.c_str();
size_t _dsize = 2 * ws.size() + 1;
char* _dest = new char[_dsize];
memset(_dest, 0x0, _dsize);
wcstombs_s(&i, _dest, _dsize, _source, _dsize);
std::string result = _dest;
delete[] _dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
修改如下代碼:
std::shared_ptr<std::fstream> AlibabaCloud::OSS::GetFstreamByPath(
const std::string& path, const std::wstring& pathw,
std::ios_base::openmode mode)
{
#ifdef _WIN32
if (!pathw.empty()) {
return std::make_shared<std::fstream>(ws2s(pathw), mode);
}
#else
((void)(pathw));
#endif
return std::make_shared<std::fstream>(path, mode);
}
修改文件src/utils/ResumableBaseWorker.cc
#include <string>
#include <algorithm>
#ifdef _WIN32
#include <codecvt>
#include <locale>
#endif
#include <alibabacloud/oss/Const.h>
#include "ResumableBaseWorker.h"
#include "../utils/FileSystemUtils.h"
#include "../utils/Utils.h"
編譯:
mkdir build
cd build
cmake -G "Unix Makefiles" ../
mingw32-make.exe