2

I am trying to wrap the ONNX header for use in another language. To be clear it uses the C dll and requires the C header however I'm having issues compiling using the C header due to the ONNX header seemingly missing the definition of the OrtEnv struct that is used in the current ONNX samples.

https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/session/onnxruntime_c_api.h

This is the ONNX api header that I'm trying to use to wrap.

And the sample

https://github.com/microsoft/onnxruntime/blob/master/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp

On line 30 it declares a raw pointer to a struct I cannot find the definition of in the api header thenless I do not understand something.

Could someone possibly elaborate on what I am doing wrong? All I can see is method declarations returning OrtEnv but never the type declaration.

There is a complete dynamic package available here with the header:

https://github.com/microsoft/onnxruntime/releases/download/v1.4.0/onnxruntime-win-x64-gpu-1.4.0.zip

where it should be simple to link the dll to your application and include the aforementioned header that im having issues with.

D3181
  • 2,037
  • 5
  • 19
  • 44
  • What language are you writing *your* program in? That should be the only language tag used, even if you use a library written in C. – Some programmer dude Sep 13 '20 at 10:35
  • Not really the complaint is from vcc since its wrapped using nim which outputs to c and links the dll and so uses vcc but even independently using vcc It can't find OrtEnv so being unable to find the definition of OrtEnv in the C header is in fact the problem not the wrapping. Plus as I said iv reviewed the header the only reference to ortenc I find is an pointer in the function defs – D3181 Sep 13 '20 at 10:37

1 Answers1

2

If a header does not contain a definition, it means that the author did not want to give it to you. That can happen for various legitimate reasons, one of them is that you should not be able to tamper with the content.

  • I would agree, except the sample iv linked uses the raw pointer to the struct in question on line 30 and the header itself references a pointer to the struct but without defining it which is why I'm confused about its appearance/existence. So either the samples are incorrect or I'm doing something wrong with defines or... I don't know – D3181 Sep 13 '20 at 11:01
  • There is nothing wrong with using a pointer to an unknown structure. This limits the repertoire of operations available for such a pointer: you cannot dereference it and you cannot increment it. But otherwise it is OK. – Christopher Yeleighton Sep 13 '20 at 11:04
  • 1
    `OrtEnv` is defined inside `onnxruntime/core/session/ort_env.h`, which is not in `include` directory, meaning you shouldn't be needing it. Do you get any compiler/linker error or you're just confused about how it works? – Maciej Dziuban Sep 13 '20 at 11:15
  • The compiler complains linking I will pos the exact error when I can but its a definition error due to it not finding OrtEnv. I was also confused how it works since I too couldn't find the definition in the header and the sample only includes the header I linked and so I'm unsure how the sample application also managed to compile using a raw pointer to an undefined struct that I couldn't find. What Christopher said is true but I'm unsure how I can defined a pointer to a type that isn't known from the header to link to a dll. By this I also mean shouldnt it be a void* if the type is unknown? – D3181 Sep 13 '20 at 11:21
  • 1
    The only way to get a pointer to an unknown struct is to get it from the library where it is defined. – Christopher Yeleighton Sep 13 '20 at 11:27
  • Yes exactly, i agree so my issue then is how in the sample code have they achieved on line 30 a pointer to a struct where the type of struct aka OrtEnv* when OrtEnv* defintion doesent exist in the only header that is in theory included? it seems to me the sample is broken or im misunderstanding something because it isnt available to define.... – D3181 Sep 13 '20 at 12:21