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".