Sign in to follow this  
Malder

Unresolved external symbol linking error

Recommended Posts

I have been trying to go through a DirectX tutorial at https://www.directxtutorial.com. I am assuming the code is correct, yet I keep getting linking errors. I want to get this working so I can at least play around with the code while I am following along through the tutorial. I have tried looking through the forums for help, without any luck. I found other posts with similar issues, but nothing I could use. I am using Visual Studio 2005 and have already installed Microsoft DirectX SDK (Nov 2008). I also have already tried manually adding both library and header files to the path directory. Keep in mind that I am very new at this. Thank you for any help! Here is the code:
// blah.cpp : Defines the entry point for the console application.

#include <stdafx.h>
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")

// global declarations
LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class

// function prototypes
void initD3D(HWND hWnd);    // sets up and initializes Direct3D
void render_frame(void);    // renders a single frame
void cleanD3D(void);    // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300, 300,
                          800, 600,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    initD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT)
            break;

        render_frame();
    }

    // clean up DirectX and COM
    cleanD3D();

    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D


    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
}


// this is the function used to render a single frame
void render_frame(void)
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D
}

[Edited by - Malder on June 21, 2009 1:36:36 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Malder
I also have already tried manually adding both library and header files to the path directory.


The path being your project directory, or the %PATH%? No matter, because you should configure the directories from Visual Studio and not from your paths. Go to
Tools->Options->Projects and Solutions->VC++ Directories*, select "Include Files" from the combo box under "Show directories for" label, and add a new entry, and navigate to the include directory of your DirectX SDK include directory. Select "Library files", and do the same for the DirectX SDK libraries directory. Lather, rinse, and repeat.

*If the "VC++ Directories" item does not appear under the options menu, load a C++ project, and try again.

Also, use [source][/source] tags to format your code in a pretty box.

Share this post


Link to post
Share on other sites
Source tags are your friend. You didn't tell us what externals are unresolved (exactly what errors is the compiler giving you?). It could be anything, so without further knowledge we can't really help. But make sure you're linking to the required libs, like the DirectX libs or whatever other 3rd party libraries you're using.

[edit]

ninja'd++;

Share this post


Link to post
Share on other sites
Quote:
The path being your project directory, or the %PATH%? No matter, because you should configure the directories from Visual Studio and not from your paths. Go to
Tools->Options->Projects and Solutions->VC++ Directories*, select "Include Files" from the combo box under "Show directories for" label, and add a new entry, and navigate to the include directory of your DirectX SDK include directory. Select "Library files", and do the same for the DirectX SDK libraries directory. Rinse, lather, and repeat.

*If the "VC++ Directories" item does not appear under the options menu, load a C++ project, and try again.

Also, use [source][/source] tags to format your code in a pretty box.


Sorry, I actually did just configure the directories in the VC ++ directory and did not mess with the %PATH% as you mentioned above and I forgot to use tags to format the code.

Here is what message I recieved after trying to build the project:

1>Linking...
1>MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol __imp__InterlockedExchange@8 referenced in function ___tmainCRTStartup
1>MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol __imp__Sleep@4 referenced in function ___tmainCRTStartup
1>MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol __imp__InterlockedCompareExchange@12 referenced in function ___tmainCRTStartup
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__QueryPerformanceCounter@4 referenced in function ___security_init_cookie
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetTickCount@0 referenced in function ___security_init_cookie
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentThreadId@0 referenced in function ___security_init_cookie
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentProcessId@0 referenced in function ___security_init_cookie
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetSystemTimeAsFileTime@4 referenced in function ___security_init_cookie
1>MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__FatalAppExitA@8 referenced in function ___security_init_cookie
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__RaiseException@16 referenced in function "int __cdecl DebuggerProbe(unsigned long)" (?DebuggerProbe@@YAHK@Z)
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__DebugBreak@0 referenced in function "void __cdecl failwithmessage(void *,int,int,char const *)" (?failwithmessage@@YAXPAXHHPBD@Z)
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__WideCharToMultiByte@32 referenced in function "void __cdecl failwithmessage(void *,int,int,char const *)" (?failwithmessage@@YAXPAXHHPBD@Z)
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__IsDebuggerPresent@0 referenced in function "void __cdecl failwithmessage(void *,int,int,char const *)" (?failwithmessage@@YAXPAXHHPBD@Z)
1>MSVCRTD.lib(gs_report.obj) : error LNK2001: unresolved external symbol __imp__IsDebuggerPresent@0
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__MultiByteToWideChar@24 referenced in function "void __cdecl failwithmessage(void *,int,int,char const *)" (?failwithmessage@@YAXPAXHHPBD@Z)
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__lstrlenA@4 referenced in function "void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)" (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__GetProcAddress@8 referenced in function "void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)" (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2001: unresolved external symbol __imp__GetProcAddress@8
1>MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__LoadLibraryA@4 referenced in function "void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)" (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2001: unresolved external symbol __imp__LoadLibraryA@4
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__HeapFree@12 referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__HeapAlloc@12 referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__GetProcessHeap@0 referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__GetModuleFileNameW@12 referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__VirtualQuery@12 referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__FreeLibrary@4 referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
1>MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__TerminateProcess@8 referenced in function ___report_gsfailure
1>MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentProcess@0 referenced in function ___report_gsfailure
1>MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__UnhandledExceptionFilter@4 referenced in function ___report_gsfailure
1>MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__SetUnhandledExceptionFilter@4 referenced in function ___report_gsfailure

Share this post


Link to post
Share on other sites
You're not linking to the correct C Runtime Library (CRT). More than likely you'll need to link to the Multi-threaded Debug DLL.

You'll need to make sure that you set your project to use the correct form of the CRT libraries. I can't think of the setting screen off the top of my head but if you're building in Debug mode you probably want to link to the Multi-Threaded Debug version. If that doesn't work, try just the Debug DLL.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by leeor_net
You're not linking to the correct C Runtime Library (CRT). More than likely you'll need to link to the Multi-threaded Debug DLL.

You'll need to make sure that you set your project to use the correct form of the CRT libraries. I can't think of the setting screen off the top of my head but if you're building in Debug mode you probably want to link to the Multi-Threaded Debug version. If that doesn't work, try just the Debug DLL.

Hope this helps.


I tried linking the Multi-Threaded Debug version and it just failed to build.

1>cl : Command line error D8016 : '/MTd' and '/clr' command-line options are incompatible

I just switched it back to the Multi-Threaded Debug DLL I had to set to originally. Is there anything else you can think of?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this