OpenEncodeSessionEx() fail with "invalid struct version" error

Hi there
I got stuck with a strange behavior, trying to initialize NVENC in ME-only mode. OpenEncodeSessionEx() always fail with #15 - "This indicates that an invalid struct version was used by the client."
Parameters struct is as follow:

    .deviceType = NV_ENC_DEVICE_TYPE_CUDA,
    .device = ctx,
    .reserved = 0,
    .apiVersion = NVENCAPI_VERSION,
    .reserved1 = 0,
    .reserved2 = NULL
  int ret = encOpenEncodeSessionEx(&session_params, &encoder->enc);

I tried to invoke it from C and Golang environments, but whatever I do I get that error. Encoder from ENENC samples just crashed (segfault).
Does anyone know, what exact conditions cause the error #15?
I upgraded Cuda to 10.2 with 440.82 driver - no luck. Tried to downgrade to Cuda 10.0 - still the same. I use 1060ti GPU.
Anyone help me please))

Ok, I finally figure it out.

It was so stupid of me but the problem was in the static keyword (C-language). I wrote simple wrapper to call NVENC function, like this:

static NVENCSTATUS encOpenEncodeSessionEx(NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *params, void **encoder) {
  return nvenc_api.nvEncOpenEncodeSessionEx(params, encoder);

Use it in this manner and you’re always get NV_ENC_ERR_INVALID_VERSION error. Just remove static keyword and the function works as expected.

I have no idea, if it is expected behavior or not, but it works.
Thanks to all.

It looks odd that you see this problem and then removing ‘static’ keyword of a wrapper function fixed it for you. If you could provide a way to reproduce this issue, someone can hopefully look into it to know what exactly went wrong.