problem about ruby-ffi-Collection of common programming errors


  • GeorgieF
    c++ singleton shared-libraries ffi ruby-ffi
    I am a real C++ noob, so please be patient with me. First lets set the stage.I have a C++ source in binary.cpp that compiles to a binary which looks like:# include “lotsofheaders.h”int main(int argc, char* argv[]) {int errorcode = FOOBAR_GLOBAL_UNKNOWN;// foobar instanciationFoobar foobar();// multiple calls to :send_auth passing in foobar instanceerrorcode = send_auth(getX(), getY(), foobar);errorcode = send_auth(getX(), getY(), foobar);errorcode = send_auth(getX(), getY(), foobar);return errorcode == FOOBAR_OK ? EXIT_SUCCESS : EXIT_FAILURE; }The send_auth method is loaded from another object code file and it gets passed an instance of foobar. The reason is, Foobar comes from an API object that I do not have the source of and which MUST NOT be instantiated more than once.Since main is called only once, everything works as expected: There is only one instance of Foobar and send_auth can be called multiple times.The binary is not of any use for me, I need a shared object library that does the same. It creates only one instance of Foobar and exposes an external interface method send_with_auth that can be called multiple times after my shared object lib was loaded.My library code in library.cpp looks some like this:# include “lotsof

Originally posted 2013-11-06 03:13:51.