linking error/conflict for SendMessageA method - c++

I have built the aws-cpp-sdk the following way:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DBUILD_ONLY="s3;sqs;sns"
and after that I ran:
MSBuild.exe INSTALL.vcxproj
Which produced the following files in the "*C:\Program Files\aws-cpp-sdk-all*" directory:
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
along with the include directory. I have included all the headers and all the libraries:
#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" );
But whenever I build this I get:
__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
I tried everything I could find, I even re-built the library many times with different arguments, but still the same problem persists. it seems it has something do with AWS::SQSClient::SendMessageA name conflicting with some kind of Windows method (but I'm probably wrong). There was one solution which stated, if I define this before the AWS headers, it should build:
#undef GetObject
but still the same error. Any suggestions please?

The problem is that the Windows system headers define the macro SendMessage to expand to either SendMessageA or SendMessageW depending on the existence of the UNICODE macro.
It does this for a lot of functions in the Windows API, which of course means that there will be clashes with other code using symbols that turn out to be macros in Windows.
One possible solution is to #undef SendMessage after #include <windows.h>. Which might not be possible if the code you try to build comes from a third party.

You may want to take a look at this blog post for a detailed explanation.
You may try with:
#undef SendMessage
before including the AWS headers (similarly to the #undef GetObject you cited in your question).

Related

DirectX 11 and g++ compile error

Hello I actually learning DirectX 11 with this tutorial: http://www.rastertek.com/dx11tut03.html
First Part
My code (where the probleme come from):
d3dclass.h:
//Linking
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
//Include
#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <d3dx10math.h>
I do all like the tutorial, the only diference is I compile it with g++, trough this the command :
g++ -mwindows WinMain.cpp systemclass.cpp inputclass.cpp graphicsclass.cpp d3dclass.cpp -o Prog.exe -I "D:\Programme File\DirectX SDK\Include" 2> log.txt
but in the output file, I have a large sum of errors. This is the log.txt:
https://drive.google.com/open?id=1XUlcAFUyRcLIvdKbe0FkLVjkvwxpOmEv
To sum up the log there is a lot of things like __in which has not been declared in the dxgi.h, but this header is from DirectX11 Library;
Second Part
I found the way to fix a lot of my problem (of the first part) with adding this :
#define __in
#define __out
#define __inout
#define __in_bcount(x)
#define __out_bcount(x)
#define __in_ecount(x)
#define __out_ecount(x)
#define __in_ecount_opt(x)
#define __out_ecount_opt(x)
#define __in_bcount_opt(x)
#define __out_bcount_opt(x)
#define __in_opt
#define __inout_opt
#define __out_opt
#define __out_ecount_part_opt(x,y)
#define __deref_out
#define __deref_out_opt
#define __RPC__deref_out
but there still is a major problem, this is the error output :
D:\Programme File\DirectX SDK\Include/d3dx10core.h:345:13: error: expected ';' at end of member declaration
HRESULT WINAPI_INLINE GetDesc(D3DX10_FONT_DESCA *pDesc) { return GetDescA(pDesc); }
it comes from WINAPI_INLINE (this is in the DirectX header)
How can I fix this? please.
I don't have any experience with using g++, but I can help with a few details here. To use g++ you need to install the Windows SDK and configure it to include the proper paths. The legacy DirectX SDK requires the Windows SDK and is not fully standalone.
Note that the legacy DirectX SDK and the Windows SDK don't claim to be compatible with the GCC toolchain.
The __in, __out, etc. macros are called "SAL annotations" and they are there to improve the quality of static code analysis both internally at Microsoft and when using Visual C++'s /analyze switch. They are defined as 'blank' in other cases so they just get removed from the code. The macros are defined in the Windows SDK. You can try explicitly doing a #include <sal.h> and/or #include <specstrings.h> before including a version of dxgi.h.
Another thing to keep in mind is that the legacy DirectX SDK itself is deprecated along with the D3DX9, D3DX10, and D3DX1 utility libraries. As such, if you are using the Windows 8.0, 8.1, or 10 SDK you can code Direct3D 11 without using it at all--see Living without D3DX. If you do want to continue to use those older helpers--which the somewhat dated rastertek tutorials assume--, you can do so but you need to make sure the DirectX SDK include and lib paths are searched after the Windows SDK include/lib paths.
If you were using Visual C++ (which BTW has a free Community edition available), then you'd probably be having an easier time. You might also want to see the DirectX Tool Kit tutorials.

How to install GDI+ SDK

I recently downloaded GDI+ SDK from the following link:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=18909
I have it, but it simply extracts two folders, one of which contains no code at all, just the eula.
I am not sure what you call the files I was given here. I assumed they would be a library, and should just be #included. However, c++ seems a lot less straight forward as to importing things(Java seemed a lot clearer to me on how to use external code). Then again, maybe I just haven't found that essential tutorial yet.
Either way, I am at a loss on how to incorporate GDI+ into my code.
The following site (https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx) says plainly that System.Drawing is a namespace, which to my knowledge is in GDI+. I have the following code:
#include "C:\GDI+\asms\10\msft\windows\gdiplus\gdiplus.dll"
#include <stdafx.h>
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
When trying to code the following:
using namespace System.Drawing;
I get the error: Must be a namespace name.
How should I install the SDK files so that I can use them in my projects?
Clearly, I am not doing something right.
#include is for header files only, cannot be used to add *.dll files.
using namespace System.Drawing; is for .Net, C++ doesn't know what it is
In Visual Studio use this to link to library:
#pragma comment( lib, "Gdiplus.lib" )
You also need Gdi startup and shut down.
//#pragma warning( push ) optional
//#pragma warning( disable : 4458 )
#include <gdiplus.h>
//#pragma warning( pop )
//link to library:
#pragma comment( lib, "Gdiplus.lib" )
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
//do stuff
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}

glut.h error when testing glut in code blocks

When trying to build a project using glut I get an error. Not in the main.cpp but rather in the glut.h I've included.
#pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */
#pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */
#pragma comment (lib, "glu32.lib") /* link with OpenGL Utility lib */
#pragma comment (lib, "glut32.lib") /* link with Win32 GLUT lib */
#pragma warning (disable:4244) /* Disable bogus conversion warnings. */
#pragma warning (disable:4305) /* VC++ 5.0 version of above warning. */
All of these lines are the ones who show an error with the description:
Warning: ignoring #pragma warning [-Wunkown-pragmas]
It's the same error for all of the these lines.
I also get one additional error, also in the glut.h file. It's on the line:
typedef unsigned short wchar_t;
This error reads:
error: redeclaration of built in C++ type "wchar-t" [-fpermissive]
Anyone who's got an idea of how I should go about solving this issue.
The linking seems to be fine since it realizes that the glut.h file
exist but the glut.h is the file providing the errors.

Unresolved external symbol _IID_IDXGIFactory

I create Console Application in VC++ 2010, and add the following code to it:
#include <d3d10.h>
#include <d3dx10.h>
#include <DxErr.h>
#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "dxerr.lib")
int _tmain(int argc, _TCHAR* argv[])
{
IDXGIFactory* pDXGIFactory;
CreateDXGIFactory(IID_IDXGIFactory, ( void** )&pDXGIFactory);
return 0;
}
Building this project, I have linker error: error LNK2001: unresolved external symbol _IID_IDXGIFactory
Now I create Console Application with MFC support, and add the same code. The build is successful. What is wrong in the first case? Why MFC project is built successfully, and non-MFC project fails?
You need to reference another library, which holds this identifier:
#pragma comment(lib, "windowscodecs.lib")
MSDN says its DXGI.lib but effectively at least Windows SDK 7.0 has it in a different library.
I had the same issue and In my case referencing
#pragma comment(lib, "dxgi.lib") solved the issue.

Linker problem on VS2005 with VC++

Here's the scenario:
Platform:
VS2005 and language is VC++
Situation:
There's just 1 assembly CMPW32. It has 2 projects:
1 is a DLL project called CMPW32 and the 2nd one is an .exe project called Driver
They both share the same Debug folder under the main assembly folder.
I have been able to successfully export a few functions from the DLL. The Driver project accesses 1 of these exported functions. (First of all I am not if functions need to be exported for projects in the SAME assembly to be able to use them. I can just include the header files and use the functions I think.)
Following is are a few lines of code from some files which you might find useful to analyze my problem:
//main.cpp file from the Driver project which is meant to generate Driver.exe
#pragma comment(lib, "winmm.lib")
#include <CM.h>
#include "conio.h"
#include "CMM.h"
#include "CMF.h"
#define C_M_F _T("c:\\CannedMessages.en-US")
int_tmain (int argc, TCHAR* argv [])
{
CMM myobjModel;
CMF::Read (CANNED_MESSAGES_FILE, myobjModel);
getch();
}
//CMM.h file
#ifndef C_M_M
#define C_M_M
#include "CMD.h"
#include "CMC.h"
#include "CM.h"
#define _C_M_DLL
#include "CMP.h"
class CM_DLL_API CMM
{ //some code here...
}
//CMF.h
#ifndef C_M_F
#define C_M_F
#include "CMM.h"
#define _C_M_DLL
#include "CMP.h"
class CM_DLL_API CMF
{ //some code here...
}
//CMP.h
#ifndef C_M_P
#define C_M_P
#include "CMD.h"
#define C_M_B_F _T("CannedMessages.")
#ifdef _C_M_DLL
#define CM_DLL_API __declspec( dllexport )
#else
#define CM_DLL_API __declspec( dllimport )
#endif
extern "C"
{
//list of functions to be exported..
}
ERRORS on building the solution:
Error13 error LNK2019: unresolved external symbol "public: __thiscall CMM::~CMM(void)" (??1CMM##QAE#XZ) referenced in function _wmain main.obj
Error15 fatal error LNK1120: 2 unresolved externals C:\"somepath here which I cant disclose"\Projects\CMPW32\Debug\Driver.exe
Please Note: If I choose to build only the CMPW32 DLL project, there are no errors and the CMPW32.dll file gets generated in the debug folder with the correct functions getting getting exported.
However there seems to be some linking problem that is pretty evident and I don't know what's going on. I have included every required file and also have entered the required .lib in the input of the "Project Settings". The paths have been set correctly too.
It would be really helpful if someone could help me out with this. Please lemme know if additional information required.
Thanks,
Viren
Looks like your Driver.exe project does not include the CPP source files of the CMM class, likely CMM.cpp.
or
You have declare a destructor for CMM class in your .H file (CMM.H) and forgot to implement it in the .CPP file (CMM.CPP).