structureio / OpenNI2

OpenNI2
Apache License 2.0
981 stars 449 forks source link

Works with mingw (gcc) on windows #108

Open 99991 opened 7 years ago

99991 commented 7 years ago

I recently tried to get my Kinect v1 to work again on Windows 8 with gcc and I thought it would be nice to document the process to save others some time.

I have installed:

I had to add four lines in "C:\Program Files\OpenNI2\Include\OniPlatform.h":

#ifdef __MINGW32__
#include "Win32/OniPlatformWin32.h"
#else

#if (defined _WIN32)
#   ifndef RC_INVOKED
#       if _MSC_VER < 1300
#           error OpenNI Platform Abstraction Layer - Win32 - Microsoft Visual Studio version below 2003 (7.0) are not supported!
#       endif
#   endif
#elif defined (ANDROID) && defined (__arm__)
#   include "Android-Arm/OniPlatformAndroid-Arm.h"
#elif (__linux__ && (i386 || __x86_64__))
#   include "Linux-x86/OniPlatformLinux-x86.h"
#elif (__linux__ && __arm__)
#   include "Linux-Arm/OniPlatformLinux-Arm.h"
#elif _ARC
#   include "ARC/OniPlaformARC.h"
#elif (__APPLE__)
#   include "MacOSX/OniPlatformMacOSX.h"
#else
#   error Xiron Platform Abstraction Layer - Unsupported Platform!
#endif

#endif

To compile a sample, I had to link against the dlls directly because gcc can not handle the libs. Note that gcc will link against the incompatible .libs instead of .dlls if they are in the same directory and things will not compile. I copied the SimpleViewer sample directory to my desktop for permission reasons and deleted all *.lib files in it. I also copied the OpenNI2 directory from "C:\Program Files\OpenNI2\Redist" and OpenNI2.dll into it. It looks like this:

simpleviewer

My compiler invocation in compile.bat is:

g++ main.cpp Viewer.cpp -I. -L. -I"C:/Program Files/OpenNI2/Include" -lOpenNI2 -lglut64 -lOpenGL32 -o main.exe

Other gotchas:

dustinfreeman commented 7 years ago

Instead of an issue, could this perhaps be on the wiki? https://github.com/occipital/OpenNI2/wiki