Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windos下QT调取: error: no member named 'GetObjectW' in 'AlibabaCloud::OSS::OssClient' #165

Open
zhongguanLiu opened this issue Oct 10, 2023 · 2 comments

Comments

@zhongguanLiu
Copy link

E:\QTProjects\StackedWidget\mainwindow.cpp:342: error: no member named 'GetObjectW' in 'AlibabaCloud::OSS::OssClient'
E:\QTProjects\StackedWidget\mainwindow.cpp:342: error: 'class AlibabaCloud::OSS::OssClient' has no member named 'GetObjectW'; did you mean 'GetObject'?
auto outcome = client.GetObject(request);
^
我才用CMake+vs2022编译,看样子库配置没有问题,出在了重载上。但是我在调用#include <alibabacloud/oss/OssClient.h>之前使用
#undef GetObject
#undef GetObjectW
#undef GetObjectA

却没有起到任何效果!
实在是不理解了!请各位大师指条路。

void MainWindow::on_network_uodate_clicked()
{
// OSS账号信息初始化
std::string Endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
std::string BucketName = "examplebucket";
std::string ObjectName = "exampledir/exampleobject.txt";
std::string FileNametoSave = "D:\localpath\examplefile.txt";

// 初始化网络等资源
ACOSS::InitializeSdk();

ACOSS::ClientConfiguration conf;
// 从环境变量中获取访问凭证
auto credentialsProvider = std::make_shared<ACOSS::EnvironmentVariableCredentialsProvider>();
ACOSS::OssClient client(Endpoint, credentialsProvider, conf);

// 下载Object到本地文件
ACOSS::GetObjectRequest request(BucketName, ObjectName);
request.setResponseStreamFactory([=]() {
    return std::make_shared<std::fstream>(FileNametoSave, std::ios_base::out | std::ios_base::in | std::ios_base::trunc | std::ios_base::binary);
});

**auto outcome = client.GetObject(request);**

if (outcome.isSuccess()) {
    std::cout << "GetObjectToFile success, size: " << outcome.result().Metadata().ContentLength() << " bytes" << std::endl;
} else {
    // 异常处理
    std::cout << "GetObjectToFile fail" <<
    ",code:" << outcome.error().Code() <<
    ",message:" << outcome.error().Message() <<
    ",requestId:" << outcome.error().RequestId() << std::endl;
}

// 释放网络等资源
AlibabaCloud::OSS::ShutdownSdk();

}

@linuxaged
Copy link

只有 GetObject 是宏吧,GetObjectAGetObjectW 都是函数。

#ifdef GetObject
#undef GetObject
#endif

你是不是在这个 undef 之后又引用了 windows 的哪个头文件?

@YueLu0116
Copy link

同样遇到了这个问题,能不能不要跟系统定义的宏起一样的名字啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants