error LNK2019 when trying to create a GamePad using DirectXTK - c++

I'm following the DirectXTK GamePad tutorial on how to incorparate a GamePad into my application but I'm getting an errorLNK2019 when trying to create the GamePad.
So far I've:
included GamePad.h to my Controller header file
Added
std::unique_ptr<DirectX::GamePad> mGamePad;
in my Controller class
In Controller::Init() added
mGamePad = std::make_unique<GamePad>();
And when I add that last line of code I get errors (loong ones):
DirectXTK.lib(GamePad.obj) : error LNK2019: unresolved external symbol __imp_RoGetActivationFactory referenced in function "long __cdecl ABI::Windows::Foundation::GetActivationFactory<struct ABI::Windows::Gaming::Input::IGamepadStatics>(struct HSTRING__ *,struct ABI::Windows::Gaming::Input::IGamepadStatics * *)" (??$GetActivationFactory#UIGamepadStatics#Input#Gaming#Windows#ABI###Foundation#Windows#ABI##YAJPEAUHSTRING__##PEAPEAUIGamepadStatics#Input#Gaming#12##Z)
DirectXTK.lib(GamePad.obj) : error LNK2019: unresolved external symbol WindowsCreateStringReference referenced in function "private: void __cdecl Microsoft::WRL::Wrappers::HStringReference::CreateReference(wchar_t const *,unsigned int,unsigned int)" (?CreateReference#HStringReference#Wrappers#WRL#Microsoft##AEAAXPEB_WII#Z)
fatal error LNK1120: 2 unresolved externals
In my application I already use the SpriteBatch without any problems so I'm guessing that I've done all the right things when I included DirectXTK to my solution.
I've also tried to create the GamePad using
mGamePad.reset( new GamePad() );
that I found in an older version of the tutorial.
Also.. The controller is inserted..
Any suggestions on what I'm doing wrong? Thank you!

You have to link your project with RuntimeObject.lib

When DirectX Tool Kit's GamePad class is built for Windows 10 (i.e. _WIN32_WINNT=0x0A00) it uses the new Windows.Gaming.Input Windows Runtime classes instead of XINPUT.
If you are building for the Universal Windows Platform, then you already have Windows Runtime initialized, _WIN32_WINNT=0x0a00 and are likely linking against RuntimeObject.lib.
If you are building a Windows desktop (aka Win32 or "classic" app), then first make sure you really intend to be making it for Windows 10 only. There are a plethora of different vcxproj files for DirectX Tool Kit depending on exactly what platform you are targeting. If you do want to be targeting Windows 10 only with your Windows desktop app, that's totally cool but you'll need to explicitly initialize Windows Runtime for your app.
TL;DR: If you are making a Windows desktop app that requires Windows 10, then link with RuntimeObject.lib and add this to your app initialization (replacing CoInitialize or CoInitializeEx):
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (FAILED(initialize))
return 1;
If you are not making a Windows desktop app that requires Windows 10, and you are not making a Universal Windows Platform (UWP) app, then use a different version of the DirectX Tool Kit that's built for Windows 7 compatibility.
See this post

Related

Linking errors for Qt and cvv when building OpenCV in Windows 10

I am trying to build OpenCV according to these instructions. After generating with CMake I opened OpenCV.sln in the build folder, switched to Release mode and built ALL_BUILD successfully. But when I try to build the INSTALL option under CMake, I get errors like this:
Error LNK2001 unresolved external symbol "public: virtual struct QMetaObject const * __cdecl cvv::qtutil::Signal::metaObject(void)const "
Error LNK2019 unresolved external symbol "public: void __cdecl cvv::qtutil::ZoomableImage::updateConversionResult(class cv::Mat const &,enum cvv::qtutil::ImageConversionResult)const "
...
I am installing OpenCV 4.2 on Windows 10 with Visual Studio 19. How can I solve this problem?
Here is an image of the error messages in Visual Studio:
Turning my comments into an answer:
The GitHub issue described here references similar errors to those you have posted. While the suggested "solution" seems more like a work-around, it may help resolve the issue. First, try building without the cvv module (an interactive GUI component of OpenCV), by running CMake with the BUILD_opencv_cvv variable set to OFF:
cmake -DBUILD_opencv_cvv=OFF ...
You can also set the variable using the CMake GUI, by clicking the Add Entry button, and defining BUILD_opencv_cvv to OFF.
The GitHub issue further explains that if there are still undefined reference errors after making this change, you can also try setting BUILD_opencv_world to OFF as well.
cmake -DBUILD_opencv_cvv=OFF -DBUILD_opencv_world=OFF ...
This may help get things building successfully, but it should be noted that these disabled modules will be left out of your build.

Compiling a shader using c++ (LNK2019 Error)

I'm trying to create a simple Arnold Renderer shader using visual studio based on the tutorial below. https://support.solidangle.com/display/mayatut/Creating+a+shader
I have created a win32console application with the application type set to DLL and have added my include libraries and ai.lib to the linker input.
When I try to compile the shader I'm met with
Error 1: error LNK2019: unresolved external symbol __imp__AiNodeParamRGB referenced in function "void __cdecl Parameters(struct AtList *,struct AtMetaDataStore *)" (?Parameters##YAXPAUAtList##PAUAtMetaDataStore###Z) C:\Users\matt\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj ConsoleApplication2
Error 2: error LNK2019: unresolved external symbol __imp__AiShaderEvalParamFuncRGB referenced in function "void __cdecl Evaluate(struct AtNode *,struct AtShaderGlobals *)" (?Evaluate##YAXPAUAtNode##PAUAtShaderGlobals###Z) C:\Users\matt\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj ConsoleApplication2
Any help?
You're trying to link a 64-bit library (ai.lib) to create a 32-bit dll. In other words, the linker is complaining because it doesn't understand the ai.lib architecture. The mismatch between 64 and 32-bit architectures are causing the problem. If your system is 32-bit, you can't compile the shader. If you have a 64bit system, you can set VC++ to build and compile a 64-bit dll.
On the tool bar in VC++
click on Win32 (next to debug), and open the drop-down menu.
Choose configuration manager, and under platform drop-down menu, choose x64.
Clean and build again.

Error in DirectX example from Microsoft

I'm trying to learn C++ and DirectX, got VS 2012 Express Desktop today for Windows 7. I should probably mention I already had DirectX SDK for VS 2010 installed.
The first of the 7 tutorials will compile fine, the rest are giving errors. Because the first one runs I think my include and library directories are set up fine.
Source is here, I put the .fx file in at the bottom as well as the compiler errors. If you don't want to click megafileupload it's just the DirectX draw a triangle tutorial (2) from Microsoft.
Tutorial files on megaupload
Warning 1 warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification C:\cpp\DirectX_Tutorial\C++\Tutorial02\Tutorial02.obj Tutorial02
Error 2 error LNK2019: unresolved external symbol _D3DCompileFromFile#36 referenced in function "long __cdecl CompileShaderFromFile(wchar_t *,char const *,char const *,struct ID3D10Blob * *)" (?CompileShaderFromFile##YAJPA_WPBD1PAPAUID3D10Blob###Z) C:\cpp\DirectX_Tutorial\C++\Tutorial02\Tutorial02.obj Tutorial02
Error 3 error LNK1120: 1 unresolved externals C:\cpp\DirectX_Tutorial\C++\Debug\Tutorial02.exe Tutorial02
Also is there a forum here I can rant on? C++, the Windows API, DirectX, and Visual Studio are all just so unnecessarily difficult to use.
Recheck if your import libraries are correct and if you're importing from the folder corresponding to your processor architecture.
Also, double check project's encoding, directx doesnt usually work well on encodings other than Unicode.

How to include ODBC ver 3.0 libraries in my MFC app in Visual C++ 2010?

I created my own ODBC wrapper class which handles SQL from C++ Win32 application.
I have copied and Added (as existing) this class to my MFC application.
Now I have terrible linking problems with unresolved external symbols (which were NOT present in the Win32 perfectly working app), such as this: "
Error 56
error LNK2019: unresolved external symbol _SQLSetStmtAttr#16 referenced in function
"public: int __thiscall Cosql::ODBCconnect(char *)" (?ODBCconnect#Cosql##QAEHPAD#Z)
C:\Documents and Settings.........\Cosql.obj ApplicationName
"
How can I PROPERLY include "sqlext.h" (and "sql.h") from
C:\Program Files\Microsoft SDKs\Windows\v7.0A in my MFC application or MORE importantly: How to resolve those external symbols?
Am I the only one trying to ODBC-connect from a MFC app and having this trouble ??? :O
I Just know that "SQLSetStmtAttr" function is there defined only for ODBCVER 3.0 and higher. Well ! But HOW do I set ODBCVER in my MFC app. ??? I have no idea.
EDIT: I figured out that ODBCVER is defined: 0x0380 (so it is ver. 3.8),
all functions are defined correctly by those includes: sql.h and sqlext.h ,
EDIT II: Linking ERROR persists when I convert all those methods (object) into pure functions using some global variables!
Thanx in advance.
Solved.
Solution: I created a DLL from my ODBC class and then used it in my project.
Now it is compiled independently so it does not restrict each other's INCOMPATIBLE environment and compiler settings anymore!

Compiling MFC application with /clr (step1: linking against dynamic DLLs)

I have successfully upgraded an MFC application which was compiled with an old version of Developer Studio to Visual Studio 2008. A very small number of changes were needed because of some breaking changes in MFC. Now that everything works, I'd like to take the next step and compile the solution with /clr.
To do so, I have found useful information on the MSDN web site:
How to: Migrate to /clr
How to: Compile MFC and ATL Code with /clr
Here are the steps I have taken:
Set the Runtime Library to Multi-threaded Debug DLL (/MDd).
Set the Use of MFC to Use MFC in a Shared DLL.
However, doing so prevents me from linking the project:
The reference to afxData can no longer be resolved; somehow, afxData is only visible when linking statically against MFC. In my code, I have the following declaration:
extern AFX_DATA AUX_DATA afxData;
which works fine with the statically linked MFC version.
The references to _afxThreadState and _afxWinState cannot be resolved either.
Here are the full error messages :
error LNK2001: unresolved external symbol "struct AUX_DATA afxData" (?afxData##3UAUX_DATA##A)
error LNK2001: unresolved external symbol "class CThreadLocal<class _AFX_THREAD_STATE> _afxThreadState" (?_afxThreadState##3V?$CThreadLocal#V_AFX_THREAD_STATE####A)
error LNK2001: unresolved external symbol "class CProcessLocal<class _AFX_WIN_STATE> _afxWinState" (?_afxWinState##3V?$CProcessLocal#V_AFX_WIN_STATE####A)
in case this might be related to the name mangling...
So, what can I do in order to dynamically link against MFC, but still reference afxData, _afxThreadState and _afxWinState?
When using MFC in a shared DLL, AUX_DATA must be dllimported.
extern __declspec(dllimport) AUX_DATA afxData
For thread state, rather than using template classes, use one of these
AFX_MODULE_THREAD_STATE* pState = _AFX_CMDTARGET_GETSTATE()->m_thread;
AFX_THREAD_STATE* pState = AfxGetThreadState();
Depending on the state information you require. For example, see here for some members that were moved to module state to fix a bug. Note that AfxGetModuleThreadState exists but is undocumented and could be changed in a future version.
Win state does not ring a bell, how is it used? There is probably a new way to accomplish it.