Ubuntu1604 X64 libs3 编译
来源:互联网 发布:网页空间和数据库空间 编辑:程序博客网 时间:2024/06/04 20:38
根据下面的文档,你只要在上海万根网络注册了云存储账户,就可以使用libs3生成的动态库,操作云存储了。
http://docs.openfans.org/ceph/ceph4e2d658765876863/ceph-1/ceph-object-gateway3010ceph5bf98c617f5151733011/s3-api/c
libs3在ubuntu下的编译过程:
1 下载源码,github上面最活跃的。
git clone https://github.com/bji/libs3.git
2 安装依赖库。libs3需要libxml2和liburl依赖。
sudo apt-get install libxml2sudo apt-get install libxml2-devsudo apt-get install libcurl4-openssl-dev
如果不安装会提示如下错误。 make: curl-config: Command not found make: curl-config:
Command not found make: xml2-config: Command not found make:
xml2-config: Command not found build/obj/acl.do: Compiling dynamic
object In file included from inc/response_headers_handler.h:32:0,
from inc/request.h:32,
from src/acl.c:30: inc/util.h:30:23: fatal error: curl/curl.h: No such file or directory compilation terminated.
GNUmakefile:216: recipe for target ‘build/obj/acl.do’ failed make: *
[build/obj/acl.do] Error 1如果很熟悉,可以自己下载libxml2和curl源码自己编译配置。
如果前面make 后出现错误的话,再make时,需要先清理一下,执行:
make clean
否则,会提示如下错误: make: * No rule to make target ‘curl/curl.h’, needed by
‘build/obj/acl.do’. Stop.
3 编译文件,执行 make 命令,生成build目录。
make
cd build/lib
有两个文件 libs3.a libs3.so.2
4 使用。拷贝测试的视频文件a.flv和s3-test.c文件,编译c文件,
gcc s3-test.c -ls3 -g -Wall -o s3-test
执行,效果如图:
5 测试c文件。
s3-test.c文件
#include "libs3.h"#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#define HOST "s-api.yunvm.com" // s3服务端接口主机#define KEY "test001" // 账号#define SECRET "UtbaZSpla3MJcidldKK9pvBNl6gaklG0BxWNXXXX" // 安全码#define BUCKET "video01" // bucket#define LOCALFILE "a.flv" // 本地文件// key,也就是上传到远程后,bucket下的路径和文件名称#define REMOTEPATH "test/a.flv"S3Status responsePropertiesCallback(const S3ResponseProperties* properties, void* callbackData){ printf("put properties ok"); return S3StatusOK;}static void responseCompleteCallback(S3Status status, const S3ErrorDetails* error, void* callbackData){ printf("put status:%d\n", status); return;}typedef struct put_object_callback_data { FILE* infile; uint64_t contentLength;}put_object_callback_data;static int putObjectDataCallback(int bufferSize, char* buffer, void* callbackData){ put_object_callback_data* data = (put_object_callback_data*)callbackData; int ret = 0; if(data->contentLength){ int toRead = ((data->contentLength > (unsigned)bufferSize)?(unsigned)bufferSize : data->contentLength); ret = fread(buffer, 1, toRead, data->infile); } data->contentLength -= ret; printf("send %d bytes\n", ret); return ret;}int main(int argc, char** argv){ const char *cacheControl = 0, *contentType = 0, *md5 = 0; const char *contentDispositionFilename = 0, *contentEncoding = 0; int64_t expires = -1; S3CannedAcl cannedAcl = S3CannedAclPublicRead; int metaPropertiesCount = 0; S3NameValue metaProperties[S3_MAX_METADATA_COUNT]; memset(metaProperties, 0, sizeof(metaProperties)); S3BucketContext bucketContext; S3ResponseHandler responseHandler; S3PutObjectHandler putObjectHandler; S3PutProperties S3_property = { contentType, md5, cacheControl, contentDispositionFilename, contentEncoding, expires, cannedAcl, metaPropertiesCount, metaProperties, }; S3_property.contentType = "video/x-flv"; put_object_callback_data data; struct stat statbuf; bucketContext.hostName= HOST; bucketContext.bucketName = BUCKET; bucketContext.protocol = S3ProtocolHTTP; bucketContext.uriStyle = S3UriStylePath; bucketContext.accessKeyId = KEY; bucketContext.secretAccessKey = SECRET; responseHandler.propertiesCallback = &responsePropertiesCallback; responseHandler.completeCallback = &responseCompleteCallback; putObjectHandler.responseHandler = responseHandler; putObjectHandler.putObjectDataCallback = &putObjectDataCallback; if( 0!= stat(LOCALFILE, &statbuf) ){ perror("stat local file"); return -1; } if(!( data.infile = fopen(LOCALFILE, "r") )){ perror("open local file"); return -1; } data.contentLength = statbuf.st_size; printf("file size:%ld\n", data.contentLength); S3_initialize("s3", S3_INIT_ALL, HOST); S3_put_object(&bucketContext, REMOTEPATH, data.contentLength, &S3_property, NULL, &putObjectHandler, &data); fclose(data.infile); S3_deinitialize(); return 0;}
- Ubuntu1604 X64 libs3 编译
- ubuntu1604 X64 编译 ffmpeg
- win10 vs2015 libs3 编译
- ubuntu1604
- Ubuntu1604 下编译并使用tensorflow c++库
- Qt Serial Port编译Ubuntu1604+qt4.8.7+qt create2.5.2
- X64移植编译常见问题
- 如何编译openssl x64
- 如何编译openssl x64
- X64编译总结 vs
- win7 X64 编译ffmpeg
- win7(x64)编译ffmpeg
- Openssl WIN7 x64编译
- boost Windows x64 编译
- boost x64编译
- 如何编译openssl x64
- VS2013编译Poco X64
- 苹果操作系统:安装Ubuntu1604虚拟机实例并配置bitcoin代码编译开发环境
- 国务院办公厅关于2017年 部分节假日安排的通知 (zz)
- 图像 - 灰度化、灰度反转、二值化
- Saltstack之Salt-api安装使用
- dataset for person re-id
- 使用Navicat for MySQL数据库结构同步和数据同步的方法
- Ubuntu1604 X64 libs3 编译
- 解决maven项目报错问题----指定jdk版本号
- 【Android】Error building Player: CommandInvokationFailure: Unable to convert classes into dex format.
- 日期字符串校验的问题
- Android 内存泄漏总结
- 通过ajax记录打印信息
- 如何提升自己的技术
- 第十四周项目一数组大折腾(4)创建一个长度为16的整形数组a并初始化,删除数组中所有能被3整除的元素(数组中实际有效使用的元素将不足16),输出删除后数组中的全部元素
- zookeeper windows环境 安装