error LNK2001: unresolved external symbol _D3DX10CreateTextureFromFileW#24 - c++

I am trying to call a direct X funciton but I get the following error
error LNK2001: unresolved external symbol _D3DX10CreateTextureFromFileW#24
I understand that possibly there maybe a linker issue. But I am not sure where. I inluded both d3dx10.h and the d3d10.h. I also included the d3d10.lib file. Plus, the intellisense picks up on the method as well. below is my code. The method is D3DX10CreateTextureFromFile
bool MyGame::InitDirect3D()
{
if(!DX3dApp::InitDirect3D())
{
return false;
}
ID3D10Resource* pD3D10Resource = NULL;
HRESULT hr = D3DX10CreateTextureFromFile(mpD3DDevice,
L"C:\\delete.jpg",
NULL,
NULL,
&pD3D10Resource,
NULL);
if(FAILED(hr))
{
return false;
}
return true;
}

Is the appropriate DirectX library (or libraries) configured inthe project or makefile (or whatever build system is being used)?
For this particular function , it's D3DX10.lib.

You need D3DX10.lib: http://msdn.microsoft.com/en-us/library/bb172671%28VS.85%29.aspx

Related

Compiler issue after removing CRT (DLL)

After removing the CRT from my DLL I have gotten these weird errors.
Here are they:
LNK2001 unresolved external symbol "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ)
LNK2001 unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error#std##YAXPBD#Z)
LNK2001 unresolved external symbol "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range#std##YAXPBD#Z)
unresolved external symbol __dtest
unresolved external symbol __fdtest
unresolved external symbol __invalid_parameter)noinfo_noreturn
unresolved external symbol __stdio_common_vsnprintf_s
unresolved external symbol __stdio_common_vsprintf
unresolved external symbol __std_terminate
If I understand correctly the Xbad_alloc and Xlength_error are because of the new and delete operators? In that case I create my class instance like this:
class sc_Core
{
public:
static sc_Core *Instance(void);
func A();
public:
void *operator new(size_t si)
{
return HeapAlloc(GetProcessHeap(), NULL, si);
}
void operator delete(void *pv) throw()
{
HeapFree(GetProcessHeap(), NULL, pv);
}
private:
sc_Core(void) { }
~sc_Core(void) { }
sc_Core(const sc_Core&) { }
sc_Core(sc_Core&&) {}
sc_Core& operator=(const sc_Core&) {}
sc_Core& operator=(sc_Core&&) {}
static sc_Core *p_Instance;
};
// Global Scope
sc_Core *sc_Core::p_Instance = nullptr;
sc_Core *sc_Core::Instance(void)
{
if (p_Instance == nullptr)
p_Instance = new sc_Core();
return p_Instance;
}
If anyone knows how these occur or how I can fix them it would be very much appreciated!
There's nothing weird about those errors.
Compilers are allowed to assume that they can generate code that rely on their runtime libraries. If you're going omit the runtime library at the link step, then you'll have to provide definitions for the missing symbols in your own code.
Turning off certain compiler features may reduce the number of missing symbols. You could try, for example, turning off exception handling support to see if the internal exception classes are still expected. In debug builds, the compiler may expect even more support from the runtime that in release builds.

Unresolved External Symbol- Error in guide?

So I've been trying to fix a weird bug in a game engine SDK where the Windows loading cursor is used instead of the game's own cursor.
The fix for this is here: http://www.crydev.net/wiki/index.php/Use_Custom_Cursor#Step_1:_Fixing_The_Cursor_Bug.
I have followed the fix, but I keep getting these when building the game DLL:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall MODCursor::MODCursor(void)" (??0MODCursor##QAE#XZ) referenced in function "public: __thiscall CGame::CGame(void)" (??0CGame##QAE#XZ) C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj GameDll
Error 2 error LNK2019: unresolved external symbol "public: __thiscall MODCursor::~MODCursor(void)" (??1MODCursor##QAE#XZ) referenced in function "public: virtual __thiscall CGame::~CGame(void)" (??1CGame##UAE#XZ) C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj GameDll
Yeah, normally I can fix this issue quite easily by defining the class properly, but it hasn't worked in this case. What can I be doing wrong?
The files are as they are in the guide for the fix, so there isn't really any point in posting the files here since they would be a waste of space on here. If the files are really needed to investigate this issue, I'll upload them if anyone requests them.
Perhaps there's an error within the fix itself? One possible difference from the fix to my build is that the fix is using Visual Studio 2008, I am using Visual Studio 2013.
Maybe try to put it all inside .h file:
#ifndef _MOD_CURSOR
#define _MOD_CURSOR
#include <windows.h>
#include "resource.h"
#undef GetUserName // This is a macro in windows.h, gives issues with GetUserName() of ISystem
class MODCursor : public ISystemEventListener
{
public:
MODCursor() {
gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this);
m_cursor = LoadCursor((HINSTANCE)g_hInst, MAKEINTRESOURCE(IDC_CURSOR1));
SetCursor(m_cursor);
}
~MODCursor(){
gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this);
}
private:
virtual void OnSystemEvent( ESystemEvent event,UINT_PTR wparam,UINT_PTR lparam ) {
if(event == ESYSTEM_EVENT_TOGGLE_FULLSCREEN || event == ESYSTEM_EVENT_RESIZE || event == ESYSTEM_EVENT_CHANGE_FOCUS){
if (m_cursor != GetCursor())
SetCursor(m_cursor);
}
}
HCURSOR m_cursor;
};
#endif

LNK2019: Calling a function in WinMain [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 years ago.
I've searched everywhere and can't seem to find the answer. Nobody has made anything like this apparently. I'm trying to get input from a user.
while(!done)
{
PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE);
if (msg.message == WM_QUIT) {
done = true; //if found, quit app
} else if (msg.message == WM_KEYDOWN) {
game->KeyDown(msg.wParam);
} else if (msg.message == WM_KEYUP) {
game->KeyUp(msg.wParam);
} else {
/* Translate and dispatch to event queue*/
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
When I run it it gives me the error:
error LNK2019: unresolved external symbol "public: void __thiscall Game::KeyDown(unsigned int &)" (?KeyDown#Game##QAEXAAI#Z) referenced in function _WinMain#16
I have everything defined in the header of the game class... It's subsystem is set to nothing, but the "(/SUBSYSTEM:WINDOWS)" works..
Piece of cake. "unresolved external symbol" most commonly means you declared a function without specifying what it does. Consider the following example:
void undefined();
void LNK2019()
{
undefined(); //the offending line
}
void main()
{
//doesn't even have to do anything; it's not a runtime error
}
The function LNK2019() calls undefined(), but you never told undefined() what to do. Your linker doesn't know what to make of the line. In your specific case, I'm betting Game::KeyDown doesn't have a body.
A few other comments on your code:
For Windows messages, avoid if-else trees; use switch-case. It's commonly faster, and definitely more readable.
I've never seen messages handled in a loop like that. Your Windows Procedure (whose function is commonly shortened to WndProc) should handle all Windows messages - the entire purpose of DispatchMessage is to send messages to that function.

error LNK2001: unresolved external symbol CATID_AppContainerCompatible

I am trying to register BHO with APPcontainer.Now as per the blog http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx
,I have defined following in same cpp file as DLLRegister
DEFINE_GUID(CATID_AppContainerCompatible, 0x59fb2056,0xd625,0x48d0,0xa9,0x44,0x1a,0x85,0xb5,0xab,0x26,0x40);
STDAPI DllRegisterServer(void)
{
// let ATL handle this
HRESULT hr = _AtlModule.DllRegisterServer();
ICatRegister* pcr = NULL ;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
if (FAILED(hr))
return hr;
if (SUCCEEDED(hr))
{
// Register this category as being "implemented" by
// the class.
CATID rgcatid[1] ;
rgcatid[0] = CATID_AppContainerCompatible;
hr = pcr->RegisterClassImplCategories(CLSID_ABC, 1, rgcatid);
}
When I try to compile this code I am getting following error:
unresolved external symbol CATID_AppContainerCompatible
Not sure why this is coming. I can navigate to CATID_AppContainerCompatible definition by right click on it.
any suggesitons??
I solved the issue. since DEFINE_GUID declares GUID as extern I need to put const GUID CATID_AppContainerCompatible ; in my file .After putting that statement its compiling.
DEFINE_GUID behavior depends on presence of INITGUID definition. This is a very frequent problem, so it makes no sense to repeat the details once again, here is further reading: How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID.
To avoid falling into this trap you can use __declspec(uuid(...)) specifier and let compiler sort GUIDs out automatically, e.g.:
class __declspec(uuid("{26AFA816-359E-4094-90A8-BA73DE0035FA}"))
AppContainerCompatible;
// ...
rgcatid[0] = __uuidof(AppContainerCompatible); //CATID_AppContainerCompatible;
More on this: Referencing GUIDs

error LNK2019: unresolved external symbol _luaJIT_setmode

I have this piece of code (file luascript.cpp):
bool LuaInterface::initState()
{
m_luaState = luaL_newstate();
if(!m_luaState)
return false;
luaL_openlibs(m_luaState);
#ifdef __LUAJIT__
luaJIT_setmode(m_luaState, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_ON);
#endif
registerFunctions();
if(!loadDirectory(getFilePath(FILE_TYPE_OTHER, "lib/"), false, true))
std::clog << "[Warning - LuaInterface::initState] Cannot load " << getFilePath(FILE_TYPE_OTHER, "lib/") << std::endl;
lua_newtable(m_luaState);
lua_setfield(m_luaState, LUA_REGISTRYINDEX, "EVENTS");
m_runningEvent = EVENT_ID_USER;
return true;
}
the declaration (file luajit.h):
LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
and the error is:
1>luascript.obj : error LNK2019: unresolved external symbol _luaJIT_setmode referenced in function "public: virtual bool __thiscall LuaInterface::initState(void)" (?initState#LuaInterface##UAE_NXZ)
1>C:\Users\GUIAKI\Documents\trunk.r5918\vc10\Debug\tfs.exe : fatal error LNK1120: 1 unresolved externals
How can I solve it?
Simply remove that line.
You can't link against plain Lua, if you keep it. And if you link against LuaJIT, the JIT compiler is enabled by default, anyway. That line of code is utterly pointless.
Seems like you forgot to link the library being part of "luaJIT" (never heard of it or used it).
There should be a lib file you'll have to add to your project as an additional dependency (linker settings).
Also keep in mind to include the correct headers ("lua.hpp" for C++, "luajit.h" for C).