c++ - 包含 Nvidia 的 nvapi.h 会导致编译错误

标签 c++ nvidia nvapi

我正在尝试使用 NVIDIA 的 nvapi,但我遇到了我不完全理解的编译错误。也许我使用了错误的编译器?

#include "nvapi.h"
#include <iostream>

int main()
{
    printf("Hello nvapi!");
    return 0;
}

编译: g++ nvapi_hello.cpp

输出(由于太长而被截断):

In file included from nvapi_lite_d3dext.h:35:0,
                 from nvapi.h:6,
                 from nvapi_hello.cpp:1:
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:134:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Unload();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:134:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Unload();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:134:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Unload();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:153:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetErrorMessage(NvAPI_Status nr,NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:153:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetErrorMessage(NvAPI_Status nr,NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:153:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetErrorMessage(NvAPI_Status nr,NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:174:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetInterfaceVersionString(NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:174:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetInterfaceVersionString(NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:174:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetInterfaceVersionString(NvAPI_ShortString szDesc);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:319:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GPU_GetEDID(NvPhysicalGpuHandle hPhysicalGpu, NvU32 displayOutputId, NV_EDID *pEDID);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:319:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GPU_GetEDID(NvPhysicalGpuHandle hPhysicalGpu, NvU32 displayOutputId, NV_EDID *pEDID);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:319:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GPU_GetEDID(NvPhysicalGpuHandle hPhysicalGpu, NvU32 displayOutputId, NV_EDID *pEDID);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:669:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetView(NvDisplayHandle hNvDisplay, NV_VIEW_TARGET_INFO *pTargetInfo, NV_TARGET_VIEW_MODE targetView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:669:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetView(NvDisplayHandle hNvDisplay, NV_VIEW_TARGET_INFO *pTargetInfo, NV_TARGET_VIEW_MODE targetView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:669:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetView(NvDisplayHandle hNvDisplay, NV_VIEW_TARGET_INFO *pTargetInfo, NV_TARGET_VIEW_MODE targetView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:808:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetViewEx(NvDisplayHandle hNvDisplay, NV_DISPLAY_PATH_INFO *pPathInfo, NV_TARGET_VIEW_MODE displayView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:808:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetViewEx(NvDisplayHandle hNvDisplay, NV_DISPLAY_PATH_INFO *pPathInfo, NV_TARGET_VIEW_MODE displayView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:808:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_SetViewEx(NvDisplayHandle hNvDisplay, NV_DISPLAY_PATH_INFO *pPathInfo, NV_TARGET_VIEW_MODE displayView);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1030:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetDisplayDriverVersion(NvDisplayHandle hNvDisplay, NV_DISPLAY_DRIVER_VERSION *pVersion);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1030:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetDisplayDriverVersion(NvDisplayHandle hNvDisplay, NV_DISPLAY_DRIVER_VERSION *pVersion);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1030:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetDisplayDriverVersion(NvDisplayHandle hNvDisplay, NV_DISPLAY_DRIVER_VERSION *pVersion);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1159:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1159:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1159:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1167:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1167:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1167:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1209:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1209:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1209:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsSet(NvU32 expertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1216:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1216:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1216:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_OGL_ExpertModeDefaultsGet(NvU32 *pExpertDetailLevel,
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1251:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumTCCPhysicalGPUs( NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1251:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumTCCPhysicalGPUs( NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1251:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumTCCPhysicalGPUs( NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1282:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumLogicalGPUs(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1282:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumLogicalGPUs(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
nvapi.h:99:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_Initialize();
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                          ^
nvapi.h:1282:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_EnumLogicalGPUs(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: warning: '__success' initialized and declared 'extern'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1308:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetPhysicalGPUsFromDisplay(NvDisplayHandle hNvDisp, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                         ^
nvapi.h:1308:1: note: in expansion of macro 'NVAPI_INTERFACE'
 NVAPI_INTERFACE NvAPI_GetPhysicalGPUsFromDisplay(NvDisplayHandle hNvDisp, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
 ^~~~~~~~~~~~~~~
nvapi_lite_salstart.h:821:32: note: 'int __success' previously defined here
 #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                ^
 ...

我安装了 mingw-w64 并且我使用的是 g++ 版本:

g++ (x86_64-posix-sjlj-rev2, Built by MinGW-W64 project) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我从 https://developer.nvidia.com/gameworksdownload#?search=nvapi 下载了 NVIDIA 的 NVAPI SDK

最佳答案

我找到了答案 here这解释了这些变量是在文件 nvapi_lite_salstart.h 中使用 #define 创建的,然后在文件 nvapi_lite_salend.h 中使用 #undef 取消定义。 h 分别在每个头文件的开头和结尾调用,如 nvapi.h 开头所列:

#include"nvapi_lite_salstart.h" //Remove this line
#include"nvapi_lite_common.h"
#include"nvapi_lite_sli.h"
#include"nvapi_lite_surround.h"
#include"nvapi_lite_stereo.h"
#include"nvapi_lite_d3dext.h"
#include"nvapi_lite_salstart.h" //Add this line to fix the errors

如您所见,“salstart”文件似乎只需要移动到列表的末尾,因为出于某种原因它不正确地位于顶部。不确定为什么这在 Visual Studio 中正常工作(它没有进行上述修改),但这至少修复了 MinGW 中的那些错误;然而,nVidia 提供的预编译库文件(nvapi.libnvapi64.lib)与 MinGW 不兼容,因此您不得不使用 MS Visual Studio。

关于c++ - 包含 Nvidia 的 nvapi.h 会导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43502348/

相关文章:

c++ - 使用来自另一个项目(目录)的头文件

docker - 使用 docker swarm 使用 GPU 内存作为约束来调度容器

c++ - 用于自定义分辨率和同步计时的 AMD API 与 NVIDIA NVAPI 的 NDA 版本是什么等效的?

c++ - 这个 C++ 引用示例有问题吗?

c++ - OpenGL 围绕相机移动场景

c++ - 氧气,太重而无法维持?

android - 尝试使用 NSight 编译 Android 非 native 项目

c - 为什么 cuda 中的 in-kernel-printf 在显示在显示器上之前将字符串输出到主机?

c++ - NvAPI_GPU_GetAllDisplayIds 函数未按预期工作

windows - Windows 驱动程序使用哪个编程接口(interface)来切换事件显示