OpenNI 2 and Visual Studio 2012

2019-01-18 05:41发布

问题:

I just downloaded OpenNI 2 SDK (www.openni.org) and I am trying to setup a project in Visual Studio 2012. What I did:

  1. Create a new C++ Win32 Console Application Project
  2. Go to Project>MyProject Properties and, in Configuration Properties>VC++ Directories...
  3. Added C:\Program Files (x86)\OpenNI2\Redist\; to Executable Directories
  4. Added C:\Program Files (x86)\OpenNI2\Include\; to Include Directories
  5. Added C:\Program Files (x86)\OpenNI2\Redist\; to Reference Directories
  6. Added C:\Program Files (x86)\OpenNI2\Lib\; to Library Directories

But when I try to build I have the following unresolved symbol error (where ConsoleApplication1 is my project's name)

Error   1   error LNK2019: unresolved external symbol
__imp__oniInitialize referenced in function
"public: static enum openni::Status __cdecl openni::OpenNI::initialize(void)"
(?initialize@OpenNI@openni@@SA?AW4Status@2@XZ)
c:\Users\MyPC\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj
ConsoleApplication1

I know this linking error is saying that the linker can't find some libraries but I thought what I just did was enough.

I also tried the 64 bit version, creating a 64 bit project, but I have the same errors.

I couldn't find satisfying documentation on this topic.

I'm sure I'm missing something silly. Can you please give some advice on this?

回答1:

Also you should do the below steps:

0-In the C/C++ section, under the "General" node, select

"Additional Include Directories" 

and add

"$(OPENNI2_INCLUDE)" (if you use the 32-bit version) or 
"$(OPENNI2_INCLUDE64)" (if you use the 64-bit version). 

These are environment variables that point to the location of the OpenNI Include directory. (The defaults are :

C:\Program Files\OpenNI2\Include or 
C:\Program Files (x86)\OpenNI2\Include)

1-In the Linker section, under the "General" node, select

"Additional Library Directories" 

and add

"$(OPENNI2_LIB)" (if you use the 32-bit version) or 
"$(OPENNI2_LIB64)" (if you use the 64-bit version). 

These are environment variables that point to the location of the OpenNI Lib directory. (The defaults are:

C:\Program Files\OpenNI2\Lib or 
C:\Program Files (x86)\OpenNI2\Lib)

2-In the Linker section, under the input node, select

"Additional Dependencies" 

and add

OpenNI2.lib or OpenNI2.lib

3-Ensure that you add the Additional Include and Library directories to both your Release and Debug configurations.

4-Copy all the files from OpenNI's redist directory (see environment variable "$(OPENNI2_REDIST)" or "$(OPENNI2_REDIST64)") to your working directory. (The defaults are

C:\Program Files\OpenNI2\Redist or 
C:\Program Files (x86)\OpenNI2\Redist). 

Be aware that when you run from command line, the working directory is the directory where the executable can be found, and where you run from Visual Studio the default directory is where the project file (.vcproj, .vcxproj) can be found.



回答2:

you also need to point to the actual library file: openni2.lib



回答3:

If you add all of options (Include, Lib, ...) to your project setting and again get this error, maybe your project platform is Win32 and you want to use OpenNI x64

In this case, you must change the platform to x64 (Project properties at the top of the page)

  • If you don't have x64 option, make a new one ;)