编译错误,MinGW(g++),Kinect for Windows API

3

我刚开始学习Kinect开发,想使用MinGW作为我的Kinect for Windows的开发环境。

我已经在c:\program files\Microsoft SDKS\kinect\v1.8下安装了Kinect for Windows SDK。然后按照MSDN上的这个例子,编写了一个初始化Kinect传感器的代码。

当我使用以下命令进行编译时:

g++ -c color.c -I "c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc"

我收到了很多警告和错误提示

  1. Warnings

        In file included from NuiApi.h:109:0, from color.c:2:
        c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiSensor.h:137:8: warning: extra tokens at end of #
        endif directive [enabled by default]
        #endif _Vector4_
                ^
        c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiSensor.h:160:8: warning: extra tokens at end of #
        endif directive [enabled by default]
        #endif _Matrix4_
                ^
        c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiSensor.h:209:8: warning: extra tokens at end of #
        endif directive [enabled by default]
        #endif _NUI_SKELETON_POSITION_INDEX_
        ...
        ...
    

    From I what I have searched, these warning are cause by compiler differences because Kinect SDK is intended for Visual Studio and they are egnorable.

  2. Errors

    NuiApi.h:47:5: error: definition of 'HRESULT NuiInitialize' is marked 'dllimport'
    
    NuiApi.h:47:5: error: '_In_' was not declared in this scope
    
    NuiApi.h:77:14: error: expected constructor, destructor, or type conversion before '(' token
      static_assert(E_NUI_FRAME_NO_DATA == 0x83010001, "Error code has changed.");
                   ^
    
    In file included from NuiApi.h:109:0,
                 from color.c:2:
    c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiSensor.h:2105:1: error:    '_Check_return_' does not name a type
    _Check_return_ HRESULT NUIAPI NuiGetSensorCount( _In_ int * pCount );
    ^
    ...(tons of _Check_return does not name a type)
    
    
    c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiImageCamera.h:78:39: error: '_In_'       was not declared in this scope
    c:\Program Files\Microsoft SDKs\Kinect\v1.8\inc/NuiImageCamera.h:78:70: error: '_Out_' was not declared in this scope
    

问题

我知道大多数这些错误(如果不是全部)都是因为Kinect SDK是针对VS开发的。但我是一个新手,想了解更多底层信息。所以我能否让我的g++与Kinect SDK一起使用,该怎么做? 任何帮助都将不胜感激!!

顺便说一下,这里有一个相关页面:


头文件似乎存在一些gcc不兼容性 :/。您必须使用-std=c++11标志(根据未识别的static_assert)。由于这是C ++,请使用c ++扩展名(如.cpp)而不是.c。请注意,库也可能不兼容 :-/ 祝你好运。 - Jarod42
@Jarod42 感谢您的快速回复。我添加了 -std==c++11,static_assert 被识别了。我认为大多数这些错误与 MICROSOFT 源代码注释语言有关,我正在尝试使用它。 - Tianwei Chen
2个回答

0

有一种方法! 下载 sal.hconcurrencysal.h(通过 Google 搜索找到它们)。 将它们放在 include 目录中,并在程序中包含 sal.h。
如上评论所述,添加标志 -std == c ++ 11。
然后打开 NuiSkeleton.h,在第412行和534行处将 NULL 替换为 nullptr(所有实例都要替换)。
这样就可以无错误运行了。


-1

您好,似乎您并未理解 Visual Studio 库与 MinGW 不是开箱即用兼容的。我并不是说在 MinGW 中使用 Kinect SDK 是不可能的,但您正在尝试做的事情并不容易实现。

有两个解决方案,要么您不使用 Kinect SDK(有替代品,如 OpenNI、Freenect 等),要么您使用 Visual Studio 编译您的项目(Community 版本可供个人免费使用)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接