How can you compile nvapi.h with mingw?

How can you compile nvapi.h with mingw?

What command line options are needed?

I am using “-D_WIN32 -fms-extensions” but I am getting a many errors…

In file included from …/…/include/jnvapi.h:4,
from jnvapi_wrap.c:190:
/d/opt/nvapi-r334/nvapi-334/nvapi.h:99: error: parse error before “return”
/d/opt/nvapi-r334/nvapi-334/nvapi.h: In function __success': /d/opt/nvapi-r334/nvapi-334/nvapi.h:131: error: parse error before "return" /d/opt/nvapi-r334/nvapi-334/nvapi.h:131: error: storage class specified for parameter __success’
/d/opt/nvapi-r334/nvapi-334/nvapi.h:99: error: declaration for parameter “NvAPI_Initialize” but no such parameter
/d/opt/nvapi-r334/nvapi-334/nvapi.h:131: error: declaration for parameter “__success” but no such parameter
/d/opt/nvapi-r334/nvapi-334/nvapi.h:186: error: NV_DP_1_62GBPS' undeclared (first use in this function) /d/opt/nvapi-r334/nvapi-334/nvapi.h:186: error: (Each undeclared identifier is reported only once /d/opt/nvapi-r334/nvapi-334/nvapi.h:186: error: for each function it appears in.) /d/opt/nvapi-r334/nvapi-334/nvapi.h:187: error: NV_DP_2_70GBPS’ undeclared (first use in this function)
/d/opt/nvapi-r334/nvapi-334/nvapi.h:188: error: NV_DP_5_40GBPS' undeclared (first use in this function) /d/opt/nvapi-r334/nvapi-334/nvapi.h:189: error: parse error before '}' token /d/opt/nvapi-r334/nvapi-334/nvapi.h: At top level: /d/opt/nvapi-r334/nvapi-334/nvapi.h:189: warning: data definition has no type or storage class /d/opt/nvapi-r334/nvapi-334/nvapi.h:316: error: parse error before "return" /d/opt/nvapi-r334/nvapi-334/nvapi.h:316: error: redefinition of '__success' /d/opt/nvapi-r334/nvapi-334/nvapi.h:131: error: previous definition of '__success' was here /d/opt/nvapi-r334/nvapi-334/nvapi.h: In function __success’:
/d/opt/nvapi-r334/nvapi-334/nvapi.h:350: warning: enum defined inside parms
/d/opt/nvapi-r334/nvapi-334/nvapi.h:350: error: storage class specified for parameter `NV_GPU_CONNECTOR_TYPE’

I think NVAPI is Windows only: http://docs.nvidia.com/tegra/Content/3DV_Using_NVAPI.html

MinGW is Windows only as well. I have the same question. Can I use NVAPI with MinGW?

(I’m resurrecting this thread because it was never answered. If it was answered elsewhere, please let me know.)

I know the NVAPI can be compiled with (some version of) gcc itself, because the author of this: https://github.com/tliron/opengl-3d-vision-bridge (which is what I’m trying to use the NVAPI for) has done it. However, he used gcc hosted on a Linux system to cross-compile for Windows.

It’s probably just a simple command line argument that switches the “version” of C gcc is looking for, but I don’t know what version or what argument to use.

Errors regarding “__success” are reported because of including of header files in nvapi.h in wrong order.

Before main explanation some words about how Nvidia implement SAL (https://docs.microsoft.com/en-us/visualstudio/code-quality/understanding-sal) in NVAPI:

  • header file “nvapi_lite_salstart.h” defines annotations and “nvapi_lite_salend.h” undefines them, in particular, __success() is a macro representing an annotation,
  • other header files (nvapi_lite_common.h, nvapi_lite_sli.h, etc.) include nvapi_lite_salstart.h at their beginning to define annotations and include nvapi_lite_salend.h at their end to undefine annotations.

Obviously It is a workaround for those building environments which don’t have sal.h or don’t include sal.h automatically (probably all envs but Visual Studio and company) but I don’t know why Nvidia made this in such strange manner.

So, the explanation:

  • nvapi.h includes nvapi_lite_salstart.h, at this moment annotations are defined,
  • then includes nvapi_lite_common.h which, in its turn, includes nvapi_lite_salstart.h at the beginning and nvapi_lite_salend.h at the end,
  • then includes nvapi_lite_sli.h and so on,
  • so, after all #include directives annotations are undefined, but nvapi.h uses them and compiler raises an errors.

I put ‘#include"nvapi_lite_salstart.h"’ after all include directives in nvapi.h and my program began to compile with MinGW on Linux. But not to link.
MinGW linker gives an errors:
… undefined reference to __security_check_cookie' ... undefined reference to __GSHandlerCheck’

These are because of known issue with bufferoverflowu.lib.
I haven’t found a solution yet.

Have you managed to link it by any chance? I’m struggling with the same.

Please add a MinGW support to the nvapi SDK