0

I want to use nlohmann/json library with my intel pin tool.

As directed in the document, I downloaded the json.hpp file and I'm including that in the pin tool. But, I am getting a bunch of errors something like (when I try to make):

$head error.log
In file included from /usr/include/c++/8/x86_64-redhat-linux/bits/c++config.h:2452,
                 from /usr/include/c++/8/initializer_list:41,
                 from json.hpp:42,
                 from inscount0.cpp:4:
/usr/include/c++/8/x86_64-redhat-linux/bits/os_defines.h:44:19: error: missing binary operator before token "("
 #if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
                   ^
In file included from /usr/include/c++/8/bits/stl_algobase.h:61,
                 from /usr/include/c++/8/array:40,
                 from json.hpp:60,
$ less error.logs
$ head error.logs
In file included from /usr/include/c++/8/x86_64-redhat-linux/bits/c++config.h:2452,
                 from /usr/include/c++/8/initializer_list:41,
                 from json.hpp:42,
                 from inscount0.cpp:4:
/usr/include/c++/8/x86_64-redhat-linux/bits/os_defines.h:44:19: error: missing binary operator before token "("
 #if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
                   ^
In file included from /usr/include/c++/8/bits/stl_algobase.h:61,
                 from /usr/include/c++/8/array:40,
                 from json.hpp:60,

These are just few examples, though there are too many errors like these (I can post the whole error log file if someone wants). I am sure there must be some type conflict.

I also tried to use this library with a simple cpp code and it worked fine. I don't know what I am missing here.

Edit:

My code:

#include <iostream>
#include <fstream>
#include "pin.H"
#include "json.hpp"

ofstream OutFile;

// The running count of instructions is kept here
// make it static to help the compiler optimize docount
static UINT64 icount = 0;

// This function is called before every instruction is executed
VOID docount()
{
  icount++;
}

// Pin calls this function every time a new instruction is encountered
VOID Instruction(INS ins, VOID *v)
{
    // Insert a call to docount before every instruction, no arguments are passed
    INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END);
}

KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool",
    "o", "inscount.out", "specify output file name");

// This function is called when the application exits
VOID Fini(INT32 code, VOID *v)
{
  std::cout << icount << '\n';
  /*
    // Write to a file since cout and cerr maybe closed by the application
    OutFile.setf(ios::showbase);
    OutFile << "Count " << icount << endl;
    OutFile.close();
  */
}

INT32 Usage()
{
    cerr << "This tool counts the number of dynamic instructions executed" << endl;
    cerr << endl << KNOB_BASE::StringKnobSummary() << endl;
    return -1;
}

int main(int argc, char * argv[])
{
    // Initialize pin
    if (PIN_Init(argc, argv)) return Usage();

    OutFile.open(KnobOutputFile.Value().c_str());

    // Register Instruction to be called to instrument instructions
    INS_AddInstrumentFunction(Instruction, 0);

    // Register Fini to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);

    // Start the program, never returns
    PIN_StartProgram();

    return 0;
}

Note that this is a simple pin tool (exactly the same example used in the documentation) which counts the number of instructions (see the documentation). The example is working fine, without the inclusion of "json.hpp".

R4444
  • 2,016
  • 2
  • 19
  • 30
  • 1
    I know for a fact that nlohman's json code is correct (I use it in my codebase extensively). The issue is most likely in your code, which you conveniently didn't show. – SergeyA Aug 08 '19 at 21:11
  • my code is working fine without the library - but when I try to include it - #include it gives me errors, so I don't see a problem with my code here. Also, I know that the code is correct (that's why i mentioned that it worked fine with the simple cpp code but not when I include it in my pin tool). – R4444 Aug 08 '19 at 21:12
  • @SergeyA I updated the question with the example. – R4444 Aug 08 '19 at 21:22
  • 2
    See [this question](https://stackoverflow.com/questions/39691080/intel-pin-with-c14). Intel PIN comes with its own STL library that is not compatible with C++11. – rustyx Aug 08 '19 at 21:35
  • Thanks rustyx, in that case is it not possible to use this library with pin (forgive my ignorance)? – R4444 Aug 08 '19 at 21:40

0 Answers0