libs/linux/libcossdk.a #linux 的静态库,libcossdk.a 是基于 gcc version 4.8.5版本编译的,如果客户编译环境的gcc版本不同,需要重新编译libcossdk.alibs/linux/libcossdk-shared.so #linux 动态库libs/Win32/cossdk.lib #Win32库libs/x64/cossdk.lib #Win64 库libs/macOS/libcossdk.a #macOS 静态库libs/macOS/libcossdk-shared.dylib #macOS 动态库
third_party/lib/linux/poco/ #linux下依赖的 poco 动态库,poco 库是基于 OpenSSL 1.0.2版本编译的,如果客户编译环境的openssl版本不同,需要重新编译pocothird_party/lib/Win32/openssl/ #Win32依赖的 openssl 库third_party/lib/Win32/poco/ #Win32依赖的 poco 库third_party/lib/x64/openssl/ #Win64依赖的 openssl 库third_party/lib/x64/poco/ #Win64依赖的 poco 库third_party/lib/macOS/poco/ #macOS 依赖的 poco 库
option(BUILD_UNITTEST "Build unittest" OFF) #配置编译单元测试option(BUILD_DEMO "Build demo" ON) #配置编译 demo 测试代码option(BUILD_SHARED_LIB "Build shared library" OFF) #配置编译动态库
yum install -y gcc gcc-c++ make cmake openssl#cmake版本要求大于2.8
cd ${cos-cpp-sdk}mkdir -p buildcd buildcmake ..make
cd ${cos-cpp-sdk}sh install-libpoco.sh
cd ${cos-cpp-sdk}vim demo/cos_demo.cpp #修改 demo 中的存储桶名以及测试代码vim CMakeLists.txt #修改根目录下的 CMakeLists.txt 中的 BUILD_DEMO 为 ON,开启编译democd build && make #编译 demols bin/cos_demo #生成的可执行文件在 bin 目录vim bin/config.json #修改密钥和园区cd bin && ./cos_demo #运行 demo
libcossdk.a
,动态库名称为 libcossdk-shared.so
。使用时,请将库拷贝至您的工程中,同时将 include 目录拷贝至您的工程中的 include 路径下。${CMake的安装路径}\\bin
配置在 Windows 的系统环境变量 Path 中。mkdir buildcd buildcmake .. #生成 Win32 makefilecmake -G "Visual Studio 15 Win64" .. #生成 Win64 makefile
cossdk.lib
。使用时,请将库拷贝至您的工程中,同时将 include 目录拷贝至您的工程中的 include 路径下。brew install gcc make cmake openssl
cd ${cos-cpp-sdk}mkdir -p buildcd buildcmake ..make
libcossdk.a
,动态库名称为 libcossdk-shared.dylib
。使用时,请将库拷贝至您的工程中,同时将 include 目录拷贝至您的工程中的 include 路径下。PocoCrypto.so.64: undefined reference to `PEM_write_bio_PrivateKey@libcrypto.so.10'libPocoNetSSL.so.64: undefined reference to `X509_check_host@libcrypto.so.10'ibPocoCrypto.so.64: undefined reference to `ECDSA_sign@OPENSSL_1.0.1_EC'libPocoCrypto.so.64: undefined reference to `CRYPTO_set_id_callback@libcrypto.so.10'ibPocoCrypto.so.64: undefined reference to `EVP_PKEY_id@libcrypto.so.10'libPocoNetSSL.so.64: undefined reference to `SSL_get1_session@libssl.so.10'libPocoNetSSL.so.64: undefined reference to `SSL_get_shutdown@libssl.so.10'libPocoCrypto.so.64: undefined reference to `EVP_PKEY_set1_RSA@libcrypto.so.10'libPocoCrypto.so.64: undefined reference to `SSL_load_error_strings@libssl.so.10'
wget https://github.com/pocoproject/poco/archive/refs/tags/poco-1.9.4-release.zipcd poco-poco-1.9.4-release/./configure --omit=Data/ODBC,Data/MySQLmkdir my_buildcd my_buildcmake ..make -j5
yum install -y openssl-devel
undefined reference to `qcloud_cos::CosConfig::CosConfig(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
{"SecretId":"********************************", // sercret_id 替换为用户的 SecretId,登录访问管理控制台查看密钥,https://console.tencentcloud.com/cam/capi"SecretKey":"*******************************", // sercret_key 替换为用户的 SecretKey,登录访问管理控制台查看密钥,https://console.tencentcloud.com/cam/capi"Region":"ap-guangzhou", // 存储桶地域, 替换为客户存储桶所在地域,可以在COS控制台指定存储桶的概览页查看存储桶地域信息,参考 https://console.tencentcloud.com/cos5/bucket/ ,关于地域的详情见 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1"SignExpiredTime":360, // 签名超时时间, 单位s"ConnectTimeoutInms":6000, // connect 超时时间, 单位ms"ReceiveTimeoutInms":60000, // recv 超时时间, 单位ms"UploadPartSize":10485760, // 上传文件分块大小,1M~5G, 默认为10M"UploadCopyPartSize":20971520, // 上传复制文件分块大小,5M~5G, 默认为20M"UploadThreadPoolSize":5, // 单文件分块上传线程池大小"DownloadSliceSize":4194304, // 下载文件分块大小"DownloadThreadPoolSize":5, // 单文件下载线程池大小"AsynThreadPoolSize":2, // 异步上传下载线程池大小"LogoutType":1, // 日志输出类型,0:不输出,1:输出到屏幕,2输出到syslog"LogLevel":3, // 日志级别:1: ERR, 2: WARN, 3:INFO, 4:DBG"IsDomainSameToHost":false, // 是否使用专有的 host"DestDomain":"", // 特定 host"IsUseIntranet":false, // 是否使用特定ip和端口号"IntranetAddr":"" // 特定 ip 和端口号,例如“127.0.0.1:80”}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {qcloud_cos::CosConfig config("./config.json");// 如果使用永久密钥不需要填入 token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见 https://www.tencentcloud.com/document/product/436/14048config.SetTmpToken("xxx");qcloud_cos::CosAPI cos(config);}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"void TestLogCallback(const std::string& log) {std::ofstream ofs;ofs.open("test.log", std::ios_base::app);ofs << log;ofs.close();}int main(int argc, char** argv) {qcloud_cos::CosConfig config("./config.json");config.SetLogCallback(&TestLogCallback);qcloud_cos::CosAPI cos(config);}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造创建存储桶的请求std::string bucket_name = "examplebucket-1250000000"; // 替换为用户的存储桶名,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketqcloud_cos::PutBucketReq req(bucket_name);qcloud_cos::PutBucketResp resp;// 3. 调用创建存储桶接口qcloud_cos::CosResult result = cos.PutBucket(req, &resp);// 4. 处理调用结果if (result.IsSucc()) {// 创建成功} else {// 创建存储桶失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造查询存储桶列表的请求qcloud_cos::GetServiceReq req;qcloud_cos::GetServiceResp resp;qcloud_cos::CosResult result = cos.GetService(req, &resp);// 3. 获取响应信息const qcloud_cos::Owner& owner = resp.GetOwner();const std::vector<qcloud_cos::Bucket>& buckets = resp.GetBuckets();std::cout << "owner.m_id=" << owner.m_id << ", owner.display_name=" << owner.m_display_name << std::endl;for (std::vector<qcloud_cos::Bucket>::const_iterator itr = buckets.begin(); itr != buckets.end(); ++itr) {const qcloud_cos::Bucket& bucket = *itr;std::cout << "Bucket name=" << bucket.m_name << ", location="<< bucket.m_location << ", create_date=" << bucket.m_create_date << std::endl;}// 4. 处理调用结果if (result.IsSucc()) {// 查询存储桶列表成功} else {// 查询存储桶列表失败,可以调用 CosResult 的成员函数输出错误信息,比如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造上传文件的请求std::string bucket_name = "examplebucket-1250000000"; // 替换为用户的存储桶名,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketstd::string object_name = "exampleobject"; //exampleobject 即为对象键(Key),是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为 doc/pic.jpg,替换为用户指定的对象名。qcloud_cos::PutObjectByFileReq req(bucket_name, object_name, "/path/to/local/file"); // 替换为用户指定的文件路径//req.SetXCosStorageClass("STANDARD_IA"); // 默认为 STANDARD,可以调用 Set 方法设置存储类型qcloud_cos::PutObjectByFileResp resp;// 3. 调用上传文件接口qcloud_cos::CosResult result = cos.PutObject(req, &resp);// 4. 处理调用结果if (result.IsSucc()) {// 上传文件成功} else {// 上传文件失败,可以调用 CosResult 的成员函数输出错误信息,比如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造查询对象列表的请求std::string bucket_name = "examplebucket-1250000000"; // 替换为用户的存储桶名,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketqcloud_cos::GetBucketReq req(bucket_name);qcloud_cos::GetBucketResp resp;qcloud_cos::CosResult result = cos.GetBucket(req, &resp);std::vector<qcloud_cos::Content> cotents = resp.GetContents();for (std::vector<qcloud_cos::Content>::const_iterator itr = cotents.begin(); itr != cotents.end(); ++itr) {const qcloud_cos::Content& content = *itr;std::cout << "key name=" << content.m_key << ", lastmodified ="<< content.m_last_modified << ", size=" << content.m_size << std::endl;}// 3. 处理调用结果if (result.IsSucc()) {// 查询对象列表成功} else {// 查询对象列表失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造下载对象的请求std::string bucket_name = "examplebucket-1250000000"; // 替换为用户的存储桶名,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketstd::string object_name = "exampleobject"; // exampleobject 即为对象键(Key),是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为 doc/pic.jpg,替换为用户指定的对象名。std::string local_path = "/tmp/exampleobject";// request 需要提供 appid、bucketname、object,以及本地的路径(包含文件名)qcloud_cos::GetObjectByFileReq req(bucket_name, object_name, local_path);qcloud_cos::GetObjectByFileResp resp;// 3. 调用下载对象接口qcloud_cos::CosResult result = cos.GetObject(req, &resp);// 4. 处理调用结果if (result.IsSucc()) {// 下载文件成功} else {// 下载文件失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 指定配置文件路径,初始化 CosConfigqcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 构造删除对象的请求std::string bucket_name = "examplebucket-1250000000"; // 替换为用户的存储桶名,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketstd::string object_name = "exampleobject"; // exampleobject 即为对象键(Key),是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为 doc/pic.jpg,替换为用户指定的对象名。。// 3. 调用删除对象接口qcloud_cos::DeleteObjectReq req(bucket_name, object_name);qcloud_cos::DeleteObjectResp resp;qcloud_cos::CosResult result = cos.DeleteObject(req, &resp);// 4. 处理调用结果if (result.IsSucc()) {// 删除对象成功} else {// 删除对象失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
本页内容是否解决了您的问题?