如何从C中调用AWS CPP SDK函数
How to call AWS CPP SDK functions from C
我当前正在使用S3的AWS CPP SDK,我正在尝试从C文件中调用C 文件中的函数。
我已经查找了如何从C文件调用C 功能的指南,并且我通过简单的非AWS函数成功地完成了指南。但是,当我尝试使用相同的指南使用AWS CPP SDK功能进行同样的指南时,它无法正常工作。以下是我正在运行的文件和命令。
list_buckets.cpp
#include <stdio.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
using namespace std;
extern "C" {
void listBuckets();
}
void listBuckets() {
Aws::S3::S3Client s3_client;
auto outcome = s3_client.ListBuckets();
if (outcome.IsSuccess()) {
cout << "Your Amazon S3 buckets:" << endl;
Aws::Vector<Aws::S3::Model::Bucket> bucket_list = outcome.GetResult().GetBuckets();
for (auto const &bucket : bucket_list) {
cout << " * " << bucket.GetName() << endl;
}
} else {
cout << "ListBuckets error: " << outcome.GetError().GetExceptionName() << " - " << outcome.GetError().GetMessage() << endl;
}
}
int main(int argc, char const *argv[]) {
Aws::SDKOptions options;
Aws::InitAPI(options);
cout << "Listing buckets from list_buckets.cpp" << endl;
listBuckets();
Aws::ShutdownAPI(options);
return 0;
}
list_buckets.h
#include <aws/core/Aws.h>
void listBuckets();
list_buckets.c
#include "list_buckets.h"
int main(int argc, char const *argv[]) {
Aws::SDKOptions options;
Aws::InitAPI(options);
printf("Listing buckets from list_buckets.cn");
listBuckets();
Aws::ShutdownAPI(options);
return 0;
}
要运行list_buckets.cpp,我使用 g++ -std=c++17 -Wall -laws-cpp-sdk-core -laws-cpp-sdk-s3 list_buckets.cpp -o list_buckets && ./list_buckets
,输出为:
Your Amazon S3 buckets:
* bucket-name1
* bucket-name2
* bucket-name3
要构建用于列出AWS存储桶的库文件,我运行g++ -std=c++17 -laws-cpp-sdk-core -laws-cpp-sdk-s3 list_buckets.cpp -shared -o liblist_buckets.so
。
要运行list_buckets.c,我运行 gcc -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -L. -llist_buckets list_buckets.c
。但是,它仅产生我在下面提供的错误。
In file included from list_buckets.c:1:
In file included from ./list_buckets.h:1:
In file included from /usr/local/include/aws/core/Aws.h:17:
In file included from /usr/local/include/aws/core/utils/logging/LogLevel.h:20:
In file included from /usr/local/include/aws/core/utils/memory/stl/AWSString.h:20:
In file included from /usr/local/include/aws/core/utils/memory/stl/AWSAllocator.h:21:
In file included from /usr/local/include/aws/core/utils/memory/AWSMemory.h:20:
In file included from /usr/local/include/aws/core/utils/memory/MemorySystemInterface.h:20:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:98:1: error: unknown type name '_LIBCPP_BEGIN_NAMESPACE_STD'
_LIBCPP_BEGIN_NAMESPACE_STD
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:100:7: error: expected ';' after top level declarator
using ::size_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:100:8: error: expected identifier or '('
using ::size_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:101:7: error: expected ';' after top level declarator
using ::div_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:101:8: error: expected identifier or '('
using ::div_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:102:7: error: expected ';' after top level declarator
using ::ldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:102:8: error: expected identifier or '('
using ::ldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:104:7: error: expected ';' after top level declarator
using ::lldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:104:8: error: expected identifier or '('
using ::lldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:106:7: error: expected ';' after top level declarator
using ::atof;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:106:8: error: expected identifier or '('
using ::atof;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:107:7: error: expected ';' after top level declarator
using ::atoi;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:107:8: error: expected identifier or '('
using ::atoi;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:108:7: error: expected ';' after top level declarator
using ::atol;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:108:8: error: expected identifier or '('
using ::atol;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:110:7: error: expected ';' after top level declarator
using ::atoll;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:110:8: error: expected identifier or '('
using ::atoll;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:112:7: error: expected ';' after top level declarator
using ::strtod;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:112:8: error: expected identifier or '('
using ::strtod;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [executeListBucketsLib] Error 1
我被困在如何解决此问题上。非常感谢任何帮助/指导。
更改list_buckets.h
#include <aws/core/Aws.h>
extern "C" {
void listBuckets();
}
这告诉C编译器链接语法是什么。这会影响链接器用来解决符号的功能命名方案。
相关文章:
- 在为 iOS 构建 aws-sdk-cpp 时,cmake 上的 CXX 编译器错误已损坏
- 将 aws-iot-device-sdk-cpp-v2 与 CMake 结合使用
- AWS CPP SDK:将 AWSCredentials 传递给 S3Client
- 如何从C中调用AWS CPP SDK函数
- Amazon aws-cpp-sdk Index Faces 给出段错误
- AWS CPP TransferManager vs GetObjectRequest Stream to File f
- AWS CPP S3 开发工具包是否支持"传输加速"
- 是否可以在 32 位中构建 AWS-CPP-SDK
- Amazon AWS CPP SDK 获取 S3 存储桶下载进度
- AWS S3 CPP SDK读取字节多于指定的范围
- aws-sdk-cpp:如何通过代理访问 S3
- AWS-开发工具包-CPP:未解析的符号
- 如何使用适用于 S3 的 AWS 开发工具包 cpp 异步 API?
- 如何编译AWS-SDK-CPP运动
- 如何使用 AWS CPP SDK 检查 AWS S3 密钥是否存在
- 使用AWS CPP SDK拒绝Amazon S3的访问
- AWS-SDK-CPP异常处理残障,使用-FEXCEPTIONS启用
- 使用AWS-cpp-sdk时,在退出程序之前等待异步调用返回
- PutObject错误:使用AWS -cpp-sdk上传文件到AWS S3时
- 使用AWS -cpp-sdk上传avi文件到AWS S3