Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
BalinKingOfMori's avatar
BalinKingOfMori
Honored Guest
11 years ago

Visual Studio 2013 Linker Errors

I'm using VS2013 Pro with the DK2 SDK, and I'm getting the following linker errors:
Error	1	error LNK2001: unresolved external symbol "public: static struct ovrHmdDesc_ const * const Globals::hmd" (?hmd@Globals@@2PBUovrHmdDesc_@@B)	C:\Users\jgros_000\Documents\Visual Studio 2015\Projects\Oculus Rift DK2 Template\Oculus Rift DK2 Template\Main.obj	Oculus Rift DK2 Template

and
Error	2	error LNK2001: unresolved external symbol "public: static struct ovrSizei_ Globals::resolution" (?resolution@Globals@@2UovrSizei_@@A)	C:\Users\jgros_000\Documents\Visual Studio 2015\Projects\Oculus Rift DK2 Template\Oculus Rift DK2 Template\Main.obj	Oculus Rift DK2 Template

Oculus Rift DK2 Template is the project name, and the code is below:
#pragma once
#pragma comment(lib, "Ws2_32.lib")
#include "OVR_CAPI.h"
#include "Kernel/OVR_Math.h"
#define of(x, y) y->x

struct Globals
{
public:
static ovrHmd hmd;
static ovrSizei resolution;
};

struct CurrentState
{
public:
float yaw;
float eyePitch;
float eyeRoll;
};

void initializeRift()
{
if (Globals::hmd)
{
throw "HMD already initialized!";
}

ovr_Initialize();

Globals::hmd = ovrHmd_Create(0);

if (!Globals::hmd)
{
Globals::resolution = of(Resolution, Globals::hmd);

// TODO: get more HMD specs
}

ovrHmd_ConfigureTracking(Globals::hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
}

CurrentState getState()
{
if (!Globals::hmd)
{
throw "HMD not initialized!";
}

CurrentState result;

ovrTrackingState ts = ovrHmd_GetTrackingState(Globals::hmd, ovr_GetTimeInSeconds());

if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked))
{
OVR::Posef pose = ts.HeadPose.ThePose;
float yaw, eyePitch, eyeRoll;
pose.Rotation.GetEulerAngles<OVR::Axis::Axis_Y, OVR::Axis::Axis_X, OVR::Axis::Axis_Z>(&yaw, &eyePitch, &eyeRoll);
result.yaw = yaw;
result.eyePitch = eyePitch;
result.eyeRoll = eyeRoll;
}

return result;
}

void destroyRift()
{
if (!Globals::hmd)
{
throw "HMD not initialized!";
}

ovrHmd_Destroy(Globals::hmd);
ovr_Shutdown();
}

and
#include "Rift.h"

#include <iostream>

int main()
{
initializeRift();

// TODO: Insert application logic
std::cout << (!Globals::hmd) << std::endl;

destroyRift();

return 0;
}

Thanks for the help!

6 Replies

  • Are you sure you're using VS 2013 ?
    From your log it looks like it is VS 2015.
  • Have you installed the "Direct X SDK" which is now renamed to Windows 8.1 SDK? I just personally know from building the SDK on my machine that it was very confusing. Although, the confusion was all on Microsoft's end IMO. Renaming Direct X SDK to "Windows 8.1 SDK" is very confusing when all the docs don't call their API deprecated...

    I have never seen those errors before, so don't know how much help I would be. I know you said you're running Pro, so I'm sure you already came across this, but I found that the express versions don't come bundled with the required C++ libraries. I ended up starting to learn Unity instead myself, so hope some of that was at least a bit helpful.
  • unresolved external symbol "public: static struct ovrHmdDesc_

    Double check you have the correct library folders and libraries linked?
    Start with the code samples in the SDK and rebuild them.
  • The project was originally in VS 2015 but I opened it in 2013, hoping that would make some iota of a difference... I'll just recreate the project in 2013. Is it really necessary to download Community or Express instead of Professional? How different can they be?
  • "BalinKingOfMoria" wrote:
    Is it really necessary to download Community or Express instead of Professional? How different can they be?

    Professional is around $1000+.
    Community is pretty much the same as professional, but free.
    Express is also free, but has limits.
    Express is the old crap style of free visual studio, community is the new way that is much better. But if you already (legally) have professional, there's no benefit to community.

    For the errors...
    Linker errors for unresolved external symbol mean the linker was looking for something defined in an object file (the temp file generated from a cpp) but couldn't find it. This means the thing is declared (it's in a header somewhere or has a prototype) but the actual implementation is missing. The errors say they are looking for Globals::hmd and Globals::resolution. So it knows about both of these, but can't find where they were actually allocated.

    struct Globals
    {
    public:
    static ovrHmd hmd;
    static ovrSizei resolution;
    };

    Ok, two static members of a struct.
    Here's the problem. Static members of a struct (or class) need to have their storage defined somewhere. Here in the header they are declared, so all the code knows what type they are, but you haven't actually created them somewhere in a cpp. You need to add this in a cpp file:
    ovrHmd Globals::hmd;
    ovrSizei Globals::resolution;

    This is also where you can give them initial values.
    Whichever cpp you add that to will allocate space for them in it's generated obj file. That's what the linker was searching for.
    Don't put that bit in a header, otherwise every cpp that includes the header will try to generate it's own storage for the statics, resulting in name conflicts.


    "dignifiedweb" wrote:
    Renaming Direct X SDK to "Windows 8.1 SDK" is very confusing when all the docs don't call their API deprecated...
    The api isn't deprecated or renamed.
    There used to be two primary sdks: the directx sdk (which stopped in june 2010, the last stand alone one you can download) and the windows platform sdk (contains heaps of stuff for other parts of windows).
    The directx sdk was merged into the windows platform sdk.
    One negative of this is that microsoft also decided to get rid of the direct3d9x library (note the x on the end), which provided stuff like vector and matrix classes. Any program that uses parts of d3d9x will fail to build with just the windows sdk.

    Luckily you can still install the june 2010 directx and everything works fine like it used to.