Forum Discussion
philigaultier
11 years agoHonored Guest
Use SDK with C API in a C program with C compiler?
Hi,
I wonder if it is possible to use the C API (from SDK 0.3.2) in a full C code and compile it with a C compiler?
When I try to do it the compiler says it does not know C++ things like namespace and so on.
Is there a compiling option suitable for this or the C API is just a wrapper for the SDK written in C++? In this case I would need to use a C++ compiler for my C code.
More specifically: I'm adapting a C program to the Oculus Rift and most sources files have this header:
I don't know if the question has already been asked, I have not found topics about that matter though.
Thanks for your answers.
I wonder if it is possible to use the C API (from SDK 0.3.2) in a full C code and compile it with a C compiler?
When I try to do it the compiler says it does not know C++ things like namespace and so on.
Is there a compiling option suitable for this or the C API is just a wrapper for the SDK written in C++? In this case I would need to use a C++ compiler for my C code.
More specifically: I'm adapting a C program to the Oculus Rift and most sources files have this header:
#ifdef __cplusplus
#error This source file is not C++ but rather C. Please use a C-compiler
#endif
I don't know if the question has already been asked, I have not found topics about that matter though.
Thanks for your answers.
4 Replies
- jhericoAdventurerThe Oculus SDK and the C API are written in C++. You must compile them with a C++ compiler. However, your program which uses the SDK doesn't have to be C++. It can be pure C, since the C API headers don't have any C++ stuff in them.
#ifdef __cplusplus
#error This source file is not C++ but rather C. Please use a C-compiler
#endif
Whoever did this was making a lot more work for themselves and others. C code should compile just fine in a C++ compiler. - philigaultierHonored GuestThank you!
But I don't think there are C wrappers for everything, for exampleMatrix4::Inverted()
doesn't have an equivalent in the C API I believe.
Does it mean I should write some custom wrappers to fit my needs if I take the "full C" road? - jhericoAdventurer
"philigaultier" wrote:
Thank you!
But I don't think there are C wrappers for everything, for exampleMatrix4::Inverted()
doesn't have an equivalent in the C API I believe.
Does it mean I should write some custom wrappers to fit my needs if I take the "full C" road?
Typically if you're working with an existing rendering application there will be some sort of existing math library as well. If that's the case, then you can just write code to convert from the OVR matrix structure to your own matrix structure. If, on the other hand you have no pre-existing set of functions for dealing with matrices (perhaps the code was relying on on the built-in OpenGL matrix functions or something), then it would be pretty trivial to add an ovrMatrix4_Invert() functions to the C API.
Personally, I wouldn't recommend that. You'd be far better off using a mature math library, be it in C or C++. GLM is my preferred C++ library, and if you can use C++ I'd recommend that, even if you have to write a few wrappers.
Alternatively, some people swear by the XNA Math library, which has the 'advantage' of supporting C-only compilation. Both are header-only libraries, meaning there's nothing to link, so they're much simpler to use than libraries that aren't header-only. - philigaultierHonored GuestThank you very much for your answer!
I think I'll go C++ as you said, the C code should work just fine and it will spare me some headaches :)
So the C API is more intended to be simple to use (less object oriented) in a C++ program than to be used in a C context ?
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 7 months ago
- 8 months ago