Error in DirectX example from Microsoft - c++

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.

Related

Updated Visual Studio, now wxWidgets complains about unresolved symbols

Problem description:
I have a Visual Studio 2012 C++ project which uses wxWidgets. It compiles and links perfectly.
For reasons we won't go into, I now need to make this work with Visual Studio 2015.
Having twiddled the settings and got all the code to compile, it now refuses to link because all the libraries it uses are compiled for VS 2012. OK...
I replaced all the libraries with ones compiled for VS 2015. Everything works again... except wxWidgets.
I have now spent multiple days fruitlessly trying to force wxWidgets to work. It just won't do it.
Here's what I've done so far:
Looking at the instructions at https://github.com/wxWidgets/wxWidgets/releases/, it appears I'm supposed to download and unpack two files:
wxWidgets-3.1.1-headers.7z (which contains an include folder)
wxMSW-3.1.1_vc140_Dev.7z (which contains a lib folder).
I deleted the old wxWidgets stuff, and unpacked these two new zips.
Hundreds of preprocessor errors saying it can't find some include file. It looks like the old directory structure had ...\lib\vc_lib\... rather than ..\lib\vc140_dll\..., so I tried renaming the folder. Now everything compiles successfully.
Next the linker complains that it can't find wxbmsw28ud_core.lib — which makes sense, considering I just deleted it. I changed all the filenames to be *31 rather than *28, and no more file-not-found errors.
Now I have hundreds of LNK2001 errors. For example:
Error LNK2001 unresolved external symbol "protected: static struct wxEventTable const wxDialogBase::sm_eventTable" (?sm_eventTable#wxDialogBase##1UwxEventTable##B)
I don't understand this though. If I run DumpBin.exe against wxmsw31ud_core.lib, it dumps out several megabytes of text, including:
5146A2 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
29C0 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
Version : 0
Machine : 14C (x86)
TimeDateStamp: 5A8A0543 Sun Feb 18 22:59:15 2018
SizeOfData : 00000049
DLL name : wxmsw311ud_core_vc140.dll
Symbol name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B (protected: static struct wxEventTable const wxDialogBase::sm_eventTable)
Type : data
Name type : name
Hint : 14306
Name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B
In other words, the exact symbol that VS says it can't find!
So if the symbol is in the .lib file and I can see it there, why is VS complaining that it's not in the .lib file?
Just to be 100% certain, I made a table of every single symbol that VS claims it can't find and which .lib file it's actually in:
LNK2001 ?sm_eventTable#wxDialogBase##1UwxEventTable##B wxmsw31ud_core.lib
LNK2001 ?wxTheAssertHandler##3P6AXABVwxString##H000#ZA wxbase31ud.lib
LNK2001 ?wxTrapInAssert##3_NA wxbase31ud.lib
LNK2001 ?wxConvLibcPtr##3PAVwxMBConv##A wxbase31ud.lib
LNK2001 ?wxEmptyString##3PB_WB wxbase31ud.lib
LNK2001 ?npos#wxString##2IB wxbase31ud.lib
LNK2001 ?sm_first#wxClassInfo##0PAV1#A wxbase31ud.lib
LNK2001 ?wxNullBitmap##3VwxBitmap##A wxmsw31ud_core.lib
LNK2001 ?wxNullIcon##3VwxIcon##A wxmsw31ud_core.lib
LNK2001 ?wxDefaultSize##3VwxSize##B wxmsw31ud_core.lib
LNK2001 ?wxDefaultPosition##3VwxPoint##B wxmsw31ud_core.lib
LNK2001 ?wxEVT_NULL##3HB wxbase31ud.lib
LNK2001 ?wxEVT_BUTTON##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxDefaultValidator##3VwxValidator##B wxmsw31ud_core.lib
LNK2001 ?wxButtonNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?ms_classInfo#wxDialog##2VwxClassInfo##A wxmsw31ud_core.lib
LNK2001 ?wxStaticTextNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxListCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxConvUTF8Ptr##3PAVwxMBConvStrictUTF8##A wxbase31ud.lib
LNK2001 ?ms_appInitFn#wxAppConsoleBase##1P6APAVwxAppConsole##XZA wxbase31ud.lib
LNK2001 ?ms_appInstance#wxAppConsoleBase##1PAVwxAppConsole##A wxbase31ud.lib
LNK2001 ?ms_idMainThread#wxThread##0KA wxbase31ud.lib
LNK2001 ?wxEVT_CLOSE_WINDOW##3V?$wxEventTypeTag#VwxCloseEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_SIZING##3V?$wxEventTypeTag#VwxSizeEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_COMMAND_ENTER##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxTextCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxGaugeNameStr##3QBDB wxmsw31ud_core.lib
LNK1120 28 unresolved externals
As you can see, every single symbol is listed in either wxmsw31ud_core.lib or wxbase31ud.lib, which are both configured in the project (along with several additional wxWidgets libraries as well).
I don't understand what the problem is. I don't get why it's complaining at me. But I need to make this work. Any suggestions?
Mixing compiled files from different VS versions will lead to errors ("not found" or "incompatible") in the linking stage. Also, mixing 32/64 versions will fail.
Delete (or move to a different dir) all of [old] wxWidgets stuff, specially the generated dirs and objects during a previous wxWidgets building.
Download current wxWidgets sources from official page, or the Windows installer.
Build using the proper VS solution. Taken from wxdir\docs\msw\install.txt:
Ready to use project files are provided for VC++ versions 7, 8, 9, 10,
11, 12, 14 and 15 (also known as MSVS 2003, 2005, 2008, 2010, 2012,
2013, 2015 and 2017 respectively).
Simply open wx_vcN.sln (for N=7, 8, 9, 10, 11, 12, 14, or 15) file,
select the appropriate configuration (Debug or Release, static or DLL)
and build the solution. Notice that when building a DLL configuration,
you may need to perform the build several times because the projects
are not always built in the correct order, and this may result in link
errors. Simply do the build again, up to 3 times, to fix this.
So, simply open wx_vc14.sln and build your solution. It seems you want static library, so wx gets embedded into your app; if not, select the DLL solution.
Notice that in that wxWidgets download page you can directly get the headers and the static ("Development") or dynamic ("Release DLL") already compiled files, so as to avoid wxWidgets compilation itself.
Your link error is due to the linker looking for the function in a static library, while you're linking with DLL import libraries. IOW when you write
In other words, the exact symbol that VS says it can't find!
it is just wrong because there is clearly a difference: one symbol has the __imp__ prefix and the other one doesn't.
Either rebuild your application with WXUSINDLL defined or link with static wx libraries.
And, honestly, all of us make mistakes and it may happen that you spend hours or even days on something that can be solved in minutes, but blaming your tools really doesn't help when the problem is not with them.
On top of a great help from Vadim and Ripi2, I think you are also trying to upgrade wxWidgets from version 2.8 to 3.0. This is in itself a huge task and you should consider do one properly then the other.
I'd start with the building 2.8 source statically with the compiler at hand and then try to ujpgrade the version of wxWidgets very carefully.
Thank you.
I eventually gave up and attempted to build wxWidgets from source.
It took many, many attempts, but eventually I was able to compile wxWidgets in such a way that my application now builds successfully. It seems you have to check that all the hundreds of thousands of compilation settings in VS are identical to the target application. No, it doesn't seem to be possible to automate that.
(Having said all that, compared to how nightmarishly difficult it usually is to build anything C-related from source, this was comparatively easy...)

error LNK2019 when trying to create a GamePad using DirectXTK

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

Unresolved external symbols in Visual Studio 2013 when using UHD

I can't seem to get a very simple program to compile in Visual Studio 2013. My goal is to incorporate UHD into a C++ program (UHD Driver and Libraries for Windows). I downloaded and installed the Windows UHD package.Since the library also depends on Boost, I also downloaded the appropriate Boost library. After that, I wrote a quick test program in Visual Studio 2013:
#include "stdafx.h"
#include <iostream>
#include <uhd\usrp\multi_usrp.hpp>
#include <uhd\types\device_addr.hpp>
using namespace uhd;
int main(void)
{
device_addr_t hint;
device_addrs_t dev_addrs = device::find(hint);
system("pause");
return 0;
}
In case anyone is interested, this program should locate any USRPs attached to a host PC. I defined the appropriate include paths in Visual Studio: . .
To be clear, I included two paths to the header files:
C:\Program Files (x86)\UHD\include and C:\Program Files (x86)\boost_1_55_0
and one path to the library:
C:\Program Files (x86)\UHD\lib
When I wrote the above program, Visual Studio recognized the additional include files, recognized device_addr_t as a typedef, and didn't throw any errors. However, when I built the program, I received these errors:
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::vector<class uhd::device_addr_t,class std::allocator<class uhd::device_addr_t> > __cdecl uhd::device::find(class uhd::device_addr_t const &)" (__imp_?find#device#uhd##SA?AV?$vector#Vdevice_addr_t#uhd##V?$allocator#Vdevice_addr_t#uhd###std###std##ABVdevice_addr_t#2##Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::~device_addr_t(void)" (__imp_??1device_addr_t#uhd##QAE#XZ) referenced in function "public: void * __thiscall uhd::device_addr_t::`scalar deleting destructor'(unsigned int)" (??_Gdevice_addr_t#uhd##QAEPAXI#Z) C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::device_addr_t(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0device_addr_t#uhd##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 4 error LNK1120: 3 unresolved externals C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\Debug\uhd_test.exe uhd_test
I've encountered these errors before in other programs, but I was able to resolve them relatively easily; either I would misspell a crucial include, or there would be an issue with a template class. However, in this instance, I can't seem to resolve the issue.
Any constructive input would be appreciated.
NOTE: In addition to defining the library directory path, I've explicitly added the UHD library, and I receive the same errors.
I got your example working. Here's the software versions I used since you didn't mention much in your description:
Microsoft Visual Studio 2013
VC++ Redistributable Package for VS2013 (vcredist_x86)
UHD 003.007.002, VS2013, Win32
Boost 1.56, lib32-msvc-12.0 binary package
Here are the project configuration properties you need to set in your VS2013 applications:
C/C++ -> General -> Additional Include Directories
C:\local\boost_1_56_0
C:\Program Files (x86)\uhd\include
Linker -> General -> Additional Library Directories
C:\local\boost_1_56_0\lib32-msvc-12.0
C:\Program Files (x86)\uhd\lib
Linker -> Input -> Additional Dependencies
uhd.lib
I think the last step is what's tripping you up, good luck!
I followed exactly what David Greene said, and I ended up with the same errors. Eventually I figured out that I had downloaded the 64-bit UHD, but I was using Visual Studio 2013 Express, which was a 32-bit compiler. Downloading the 32-bit version of UHD for Visual Studio 2013 solved the problem. For anyone else having this problem, double check that the compiler matches which version of UHD you install.

Using DirectXTex Library

I am trying to update my DirectX Project to the new Windows 8.1 sdk (2013 or something) and get rid of DirectX SDK june 2010. I have come far, but I am stuck at a Linker error LNK2001
Error 3 error LNK2001: unresolved external symbol "long __cdecl DirectX::CreateDDSTextureFromFile(struct ID3D11Device *,wchar_t const *,struct ID3D11Resource * *,struct ID3D11ShaderResourceView * *,unsigned int,enum DirectX::DDS_ALPHA_MODE *)" (?CreateDDSTextureFromFile#DirectX##YAJPAUID3D11Device##PB_WPAPAUID3D11Resource##PAPAUID3D11ShaderResourceView##IPAW4DDS_ALPHA_MODE#1##Z) C:\Users\DimmerFan\documents\visual studio 2013\Projects\MikaelD3D\MikaelD3D\TextureClass.obj MikaelD3D
I guess that doesnt say much. This is the code with the error:
HRESULT result;
result = DirectX::CreateDDSTextureFromFile(device, filename, nullptr, &m_texture, 0, nullptr);
if (FAILED(result))
{
return false;
}
return true;
Where I get this function DirectX::CreateDDSTextureFromFile from the DirectXTex SDK.
However I somehow fail to include this library to my Project. I dont know what could have gone wrong.
Intellisence pops up and Everything looks good. I have included the D:\DirectXTex\DDSTextureLoader To my Include Directorys and I am including #include <DDSTextureLoader.h> Thanks for any help about this error
//Mikael Törnqvist
You can try to add DDSTextureLoader.h and DDSTextureLoader.cpp to your project, DirectXTex was provided as source code, if you want to use it, you should add it to your solution/project.
You can also build the DirectXTex project yourself, and use the headers and libs.
DirectXTex's package includes the 'standalone' versions of DDSTextureLoader, WICTextureLoader, and ScreenGrab. You drop the .cpp and .h files into your project as they are not included in the DirectXTex.lib.
DirectX Tool Kit has the 'integrated' versions of those same modules, so they are in the DirectXTK.lib.
Why are there two versions of the same files you ask? See my blog post on the topic.

Updating FBX SDK Model loading from 2012.2 to 2014.1 SDK

I've just ported over and updated a bunch of FBX model loading code I had that worked with Direct X 10 to try and make it work with Direct X 11. Since that time, the FBX SDK I was using has been updated.
In my old program I linked to the following lib:
fbxsdk-2012.2-mdd.lib
Now, clearly I can't link to this as I don't have 2012.2 on my system. So, my thinking would be simply changing 2012.2 to 2014.1, but this didn't work and lead to the following error:
error LNK1104: cannot open file 'fbxsdk-2014.1-mdd.lib'
So I tried to some googleing to see what the updated version of fbxsdk-2012.2-mdd.lib is. But I can't find anything. I tried taking out linking ot the 2014.1 lib but I get the following errors:
Error 36 error LNK2019: unresolved external symbol "void __cdecl fbxsdk_2014_1::FbxAssert(char const *,char const *,unsigned int,char const *)" (?FbxAssert#fbxsdk_2014_1##YAXPBD0I0#Z) referenced in function "public: int & __thiscall fbxsdk_2014_1::FbxArray::operatorconst " (??A?$FbxArray#H#fbxsdk_2014_1##QBEAAHH#Z)
So, looking in the FBX sample directory I opened up the ViewScene sample to see what it lib it linked to and I see that it wanted the following:
libfbxsdk-md.lib
So I did the same. But, my program claims it cannot open the file. And I'm at a loss as to what to do next.
Has anyone successfully managed to load FBX models into a Directx 11 application using 2014.1? If so, what do I need to do to get the correct lib linked?
had a similar problem this is what i did ...i read it around here in stackoverflow somewhere
anyway
"first change parameters, tools->option->debugging->symbol->server,yes thenCtrl+F5,then you will see amazing things "
libfbxsdk-md.lib is in both debug/release lib folders, so Visual Studio is confused. The full debug/release lib folder path in the Visual Studio property pages must be included separately for debug/release settings.