How can we call the C++ function getRandomInt(0,10) from an Ada program?

The solution

Start by creating an Ada specification based on the C++ header file (assuming a suitably recent GCC):

gcc -c -fdump-ada-spec random_number.h

Or read this for examples on auto-generating Ada bindings from C and C++ headers.

Comment out the #includes in random_number.h. They are unused and they are repeated in random_number.cpp anyway. Save it as random_number.hpp. (This forces C++ style Ada specs rather than C style, which is essential to link to the C++ code). Generate the Ada specification automatically:

While not essential, it is recommended to write a wrapper package to hide the C interface and C types, and to make the interface look like Ada: random_wrapper.ads and random_wrapper.adb. (This constitutes a “thick binding”, while package random_number_h is a thin binding). At this point you can choose what to expose to the Ada code; I have been selective (or lazy!).