cancel
Showing results for 
Search instead for 
Did you mean: 

Oculus library linking question...

jaholtz
Honored Guest
So I'm trying to setup an incredibly simple oculus application for test purposes that just gets the orientation from the oculus and prints it to standard out (it's a terminal c++ application).

I haven't so far been able to properly link the oculus sdk to my program, and I can't find where the problem is. I haven't found anyone else with a similar problem on the internet so far, which means I'm probably doing something wrong.

Here's my problem...
All ovr functions calls are listed as undefined references. Which leads me to believe the library isn't linked the way it should be.

Here's what I've done...
I have the windows sdk downloaded and I've tried the same general linking steps with both g++ and Visual Studio. I've specified the folder/file for the header file where OVR_CAPI.h is located, and I've specified the oculus library files in libOVR/Lib as additional dependencies (and added the path to them to the search path). None of this changes anything. The header file is being located because it doesn't throw an error on the include, but it doesn't find any of the functions, even ovr_initialize is treated as undefined.

I'll admit it's been awhile since I coded a c++ project so I could just be forgetting something about library linking and it not be oculus specific, either way if anyone has any idea what I'm missing I'd appreciate any help.

If anyone wants any additional information let me know.

// Include the OculusVR SDK
using namespace std;
#include <iostream>
#include "OVR.h" // Include the OculusVR SDK

ovrHmd hmd; // The handle of the headset

void Initialization() {
// Initalize the Oculus
ovr_Initialize();
// Create an Oculus Device
hmd = ovrHmd_Create(0);
// Tracking configuration
ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation |
ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position, 0);
int frame = 0;

while (true) {
ovrHmd_BeginFrameTiming(hmd, frame);
ovrTrackingState trackState = ovrHmd_GetTrackingState(hmd, ovr_GetTimeInSeconds());
ovrQuatf curOrient = trackState.HeadPose.ThePose.Orientation;
cout << curOrient.x << " " << curOrient.y << " " << curOrient.z << curOrient.w << endl;
ovrHmd_EndFrameTiming(hmd);
frame++;
}
}

int main(int argc, const char* argv[])
{
Initialization();
}
5 REPLIES 5

cybereality
Grand Champion
Sounds like a linker issue. Maybe it can't find the .lib file or you're using the debug file on release.

Can you post the error log? I'll admit, I haven't used G++ in a while, but maybe someone else will know.

jaholtz
Honored Guest
I've tried building this with both visual studio and and g++. I'll link my error messages here, they're basically the same both places though. Other potential problems, do I need to build/rebuild and make the oculus library (windows version) before I link it into my program? The weirdest thing is that visual studio finds and recognizes the header file because I don't get any errors before build on the methods not being recognized. It's only when I go to build (and linking happens) that I get errors. I feel like I must be missing something small but I don't know what it is.

g++ errors
 g++ -IOculusSDK/LibOVR/Include -LOculusSDK/LibOVR/Lib/x64/VS2013/ -llibovr64 oculusTest.cc
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x14): undefined reference to `ovr_Initialize'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x14): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovr_Initialize'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x1e): undefined reference to `ovrHmd_Create'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovrHmd_Create'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x3f): undefined reference to `ovrHmd_ConfigureTracking'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x3f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovrHmd_ConfigureTracking'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x68): undefined reference to `ovrHmd_BeginFrameTiming'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x68): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovrHmd_BeginFrameTiming'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x6d): undefined reference to `ovr_GetTimeInSeconds'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x6d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovr_GetTimeInSeconds'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x8f): undefined reference to `ovrHmd_GetTrackingState'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`ovrHmd_GetTrackingState'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x13d): undefined reference to `ovrHmd_EndFrameTiming'
/tmp/ccogrJXU.o:oculusTest.cc:(.text+0x13d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `ovrHmd_EndFrameTiming'


visual studio errors
Error	1	error LNK2019: unresolved external symbol _ovr_Initialize referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ)	C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj	Project1
Error 2 error LNK2019: unresolved external symbol _ovrHmd_Create referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 3 error LNK2019: unresolved external symbol _ovrHmd_ConfigureTracking referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 4 error LNK2019: unresolved external symbol _ovrHmd_GetTrackingState referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 5 error LNK2019: unresolved external symbol _ovrHmd_BeginFrameTiming referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 6 error LNK2019: unresolved external symbol _ovrHmd_EndFrameTiming referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 7 error LNK2019: unresolved external symbol _ovr_GetTimeInSeconds referenced in function "void __cdecl Initialization(void)" (?Initialization@@YAXXZ) C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Project1\Source.obj Project1
Error 8 error LNK1120: 7 unresolved externals C:\Users\Silvermourn\Documents\Visual Studio 2013\Projects\Project1\Debug\Project1.exe 1 1 Project1

lamour42
Expert Protege
For VC++ adding a path is not enough. You have to specify each library individially. VC++ 2013: Project Configuration Properties --> Linker --> Input. Under additional dependencies you have to add libovrd.lib (that's the the debugging version).

You can also look up the SDK VC++ sample projects for details.

jaholtz
Honored Guest
My problem was essentially the same as the problem in this question: viewtopic.php?f=17&t=11838

Is there a document that tells me I need to link all of these other libraries (or which ones of them I actually need instead of just copying the whole list of external dependencies?)

cybereality
Grand Champion
I think these are the only libs you need in the linker.

libovr.lib (or libovrd.lib in debug)
Winmm.lib
ws2_32.lib


This is shown in the C++ samples (i.e. OculusWorldDemo) but it's somewhat confusing since D3D/GL and other stuff is mixed in. Not sure why this is not in the documentation, it could be something to add.