SendMessageA方法的链接错误/冲突

时间:2019-06-05 15:03:43

标签: c++ amazon-web-services

我通过以下方式构建了aws-cpp-sdk:

cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DBUILD_ONLY="s3;sqs;sns"

然后我跑了:

MSBuild.exe INSTALL.vcxproj

在“ * C:\ Program Files \ aws-cpp-sdk-all *”目录中生成了以下文件:

aws-c-common.dll
aws-c-event-stream.dll
aws-checksums.dll
aws-cpp-sdk-access-management.dll
aws-cpp-sdk-access-management.lib
aws-cpp-sdk-cognito-identity.dll
aws-cpp-sdk-cognito-identity.lib
aws-cpp-sdk-core.dll
aws-cpp-sdk-core.lib
aws-cpp-sdk-iam.dll
aws-cpp-sdk-iam.lib
aws-cpp-sdk-sns.dll
aws-cpp-sdk-sns.lib
aws-cpp-sdk-sqs.dll
aws-cpp-sdk-sqs.lib

aws-c-common.lib
aws-c-event-stream.lib
aws-checksums.lib

以及 include 目录。我已经包含了所有标题和所有库:

#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/AWSLogging.h>
#include <aws/sns/model/PublishRequest.h>
#include <aws/sns/model/PublishResult.h>
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/s3/model/Bucket.h>
#include <aws/sqs/SQSClient.h>
#include <aws/sqs/model/SendMessageRequest.h>

#pragma comment( lib, "aws-cpp-sdk-core.lib"         )
#pragma comment( lib, "aws-c-common.lib"         )
#pragma comment( lib, "aws-c-event-stream.lib"   )
#pragma comment( lib, "aws-checksums.lib"        )

#pragma comment( lib, "aws-cpp-sdk-core.lib"     )
#pragma comment( lib, "aws-cpp-sdk-iam.lib"  )
#pragma comment( lib, "aws-cpp-sdk-sqs.lib"      )
#pragma comment( lib, "aws-cpp-sdk-sns.lib"      )
#pragma comment( lib, "aws-cpp-sdk-cognito-identity.lib"         )
#pragma comment( lib, "aws-cpp-sdk-access-management.lib"        )

...

Aws::SQS::SQSClient                 sqs;
Aws::SQS::Model::SendMessageRequest sm_req;

sm_req.SetQueueUrl( "https://sqs.amazonaws.com/123123" );
sm_req.SetMessageBody( stringJSONFormatted.c_str() );

auto sm_out = sqs.SendMessage(sm_req);
if (sm_out.IsSuccess())
    Logger::Log( "Message sent successfully to the AWS SQS" );
else
    Logger::Log( "FAILED to send message send to AWS SQS" );

但是每当我构建它时,我都会得到:

__declspec(dllimport) public: virtual class Aws::Utils::Outcome<class Aws::SQS::Model::SendMessageResult,class Aws::Client::AWSError<enum Aws::SQS::SQSErrors> > 
__cdecl Aws::SQS::SQSClient::SendMessageA(class Aws::SQS::Model::SendMessageRequest const &)const 
(__imp_?SendMessageA@SQSClient@SQS@Aws@@UEBA?AV?$Outcome@VSendMessageResult@Model@SQS@Aws@@V?$AWSError@W4SQSErrors@SQS@Aws@@@Client@4@@Utils@3@AEBVSendMessageRequest@Model@23@@Z) 
fatal error LNK1120: 1 unresolved externals

我尝试了所有可能找到的东西,甚至使用不同的参数多次重建了库,但是仍然存在相同的问题。似乎它与 AWS :: SQSClient :: SendMessageA 名称有关,与某种Windows方法冲突(但我可能错了)。有一种解决方案指出,如果我在 AWS 标头之前定义它,则应该构建:

#undef GetObject

,但仍然是相同的错误。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

问题是Windows系统标头将宏SendMessage定义为根据SendMessageA宏的存在而扩展为SendMessageWUNICODE

它是针对Windows API中的很多函数执行的,这当然意味着在Windows中使用宏的符号将与其他代码发生冲突。

一种可能的解决方案是在#undef SendMessage之后使用#include <windows.h>。如果您尝试构建的代码来自第三方,则可能无法实现。

答案 1 :(得分:1)

您可能想看看this blog post以获得详细说明。

您可以尝试:

.glsl

之前(包括AWS标头)(类似于您在问题中引用的#undef SendMessage )。