Search code examples
c++cwindowsinterpreterembedding

How to embed CINT into a C++ app on Windows?


I would like to know how to embed CINT into a C++ code on Windows 7 or NT.

On windows7, I need to write a C++ program that reads a C++ program from an input file, runs it and counts how many lines of code were executed during the run. I found the best way to do this would be by (1) updating the read program code so that once a command in it is executed a counter value is increased (for commands like return or break the counter value will be increased before execution), and (2) executing the updated program with a C++ interpreter, reading the counter value once it returns. I would appreciate other approaches to solve this issues.

I searched the web and found CINT would be the correct interpreter to use (although old). I downloaded it from the ROOT home page, installed it and went throw the TestApp demo, but building it I got a linkage error I didn't find how to solve. Hence I need your help.

The best would be if someone can provide me a project embedding CINT in C++ code on windows, so I can test on my machine, and find my mistake.

I will appreciate any other valueable input as well.

Thanks in advance


Solution

  • A more reasonable alternative would be to modify the source file as you read it. For instance, when this is your input:

    void foo() {
      std::cout << "Hello";
      std::cout << " World" << std::endl;
    }
    

    you transform it to this:

    static int LineCounter = 0;
    extern "C" int getLineCounter() { return LineCounter; }
    
    extern "C" void foo() {
      ++LineCounter;
      std::cout << "Hello";
      ++LineCounter;
      std::cout << " World" << std::endl;
    }
    

    and pass that to a compiler. Compile it into a DLL, call LoadLibrary, GetProcAddress("foo"), and GetProcAddress("getLineCounter").