Как скомпилировать С++ программу предназначеную

Доброго времени суток!Скачал исходники интерпретатора и генератора языка malbolge на C++. Архив был *.tar.gz , я так понимаю это линуксовый формат. Когда компилю генератор на 2008-й студии то получаю кучу ошибок:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.D:\PF\Microsoft Visual Studio 9.0\VC>cd D:\mbolge-genD:\mbolge-gen>cl /EHsc mbolge-gen.cppMicrosoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86Copyright (C) Microsoft Corporation.  All rights reserved.mbolge-gen.cppd:\mbolge-gen\utils.h(27) : error C2059: syntax error : '<cv-qualifer>'d:\mbolge-gen\utils.h(38) : error C2079: 'tod' uses undefined struct 'get_tod_usecs::timeval'd:\mbolge-gen\utils.h(39) : error C3861: 'gettimeofday': identifier not foundd:\mbolge-gen\utils.h(40) : error C2228: left of '.tv_sec' must have class/struct/union        type is 'int'd:\mbolge-gen\utils.h(40) : error C2228: left of '.tv_usec' must have class/struct/union        type is 'int'D:\mbolge-gen>
Когда компилю интерпретатор:
D:\mbolge-gen>cl /EHsc interp-orig.cMicrosoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86Copyright (C) Microsoft Corporation.  All rights reserved.interp-orig.cMicrosoft (R) Incremental Linker Version 9.00.21022.08Copyright (C) Microsoft Corporation.  All rights reserved./out:interp-orig.exeinterp-orig.objinterp-orig.obj : error LNK2019: unresolved external symbol __halloc referencedin function _maininterp-orig.exe : fatal error LNK1120: 1 unresolved externalsD:\mbolge-gen>
Может я что то не так делаю? в архиве был Makefile - я так понимаю это сценарий для компиляции под линуксом? Как мне это скомпилить на студии? Исходники прикрепил. Если ошибся разделом перенесите...  mbolge_gen.tar.gz 8,25 Kb
5 ответов

Интерпретатор скомпилил. Остался только генератор:
/*  * Searches for a short Malboge program that prints the target string * by using a branch-on-memory-read based interpreter: every time a * new memory location is read, the interpreter branches off in all * possible directions (for all possible values of that location), * recursively searching for the shortest Malbolge program. *  * In effect, the program recursively searches through all possible * execution paths of a Malbolge program to find a program that prints the * desired output. *  * (C) John Markus Bjшrndalen, 2006 *  * The interpreter code is based on the Malbolge interpreter by Ben * Olmstead (1998). *  * NB: If you're mad enough to want to write Malbolge programs in the * first place, you should be cabable of finding out where the output * files are stored and how to modify this program to search for * anything else than "Hello" ;-) */ #include <string>#include <iostream>#include <exception>#include <fstream>#include <sstream>#include <map>#include <stack>#include <time.h>#include <stdlib.h>#define MAX_TRIT  59049                  // Max 10-trit value is 59049 = 3^10#ifndef _MS_UTILS__H__#define _MS_UTILS__H__/* ------------------- parameters to tune - begin ------------------- */ #define MAX_OSEARCH            10        // max number of new emits between output chars #define MAX_SEARCH_ITERS 10000000        // Max number of emits in total. May not be needed any more#if defined __x86_64__#define rdtscll(val) do { \     unsigned int a,d; \     asm volatile("rdtsc" : "=a" (a), "=d" (d)); \     (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \} while(0)extern inline unsigned long long get_timestamp(){    unsigned long long v;     rdtscll(v);    return v;}#elseextern inline unsigned long long get_timestamp(){    unsigned long long x;     asm volatile ("rdtsc;"           "movl %0, %%ecx;"          "movl %%eax, 0(%%ecx);"           "movl %%edx, 4(%%ecx);"          : : "g" (&x) : "eax", "ecx", "edx");    return x;}#endifextern inline unsigned long long get_tod_usecs(){    struct timeval tod;     gettimeofday(&tod, NULL);     return ((unsigned long long) tod.tv_sec) * 1000000LL + (unsigned long long) tod.tv_usec; }****** processor_frequency(int sample_secs);/* Integer modulo.  * c/c++ uses the "wrong" type of modulo arithmetic. See http://dbforums.com/showthread.php?t=317629 * in c++    -1 % 94 returns -1, but this may be compiler/architecture dependent!  * This function behaves the same way as the python modulo (%) operator.  */ static inline int imod(int a, int b){    int r = a % b;     if (r < 0)     return b + r; // (nb: adding negative number)    else    return r; }// Return largest of two integersstatic inline int imax(int a, int b){    return a > b ? a : b; }// modulo incrementstatic inline int modInc(int v, int m) {     return (v + 1) % m; }****** timeSince(long long start){    long long now = get_tod_usecs();     return (now - start) / 1000000.0; }#endifstd::string TARGET        = "Hello world"; int     maxAllowedProgLen = 250;  // or MAX_TRIT/* ------------------- parameters to tune - end ------------------- */ enum MB_Exception {     BRANCH_DEPTH_EXCEPTION = 42,     ILLEGAL_ADDR_EXCEPTION,     MAX_APLEN_EXCEPTION}; // Stages of the interpreters main loop, used in the interpreter interpreterenum InterpreterStage {     STAGE_IFETCH = 0,         // instruction fetch and check for infinity    STAGE_EXEC,               // execute given instruction    STAGE_MODMEM,             // modify location of memory that the Rc register currently points at    STAGE_MODINC,             // modulo increment instruction and data pointer    //     STAGE_NUMSTAGES,          // Number of stages}; /* ---------------------------------------- */ /*  * the xlat1 table translates one of the 8 legal positions to opcodes for malbolge.  * instead of going through that translation table, I use the positions as opcodes directly.  *  */ enum {     OP_READ_DATA =  7,   // 'j'    OP_READ_IP   = 65,   // 'i'    OP_ROT_RIGHT =  6,   // '*'    OP_TERNARY   = 29,   // 'p'    OP_WRITE     = 66,   // '<'    OP_READ      = 84,   // '/'    OP_TERMINATE = 48,   // 'v'    OP_NOP       = 35,   // 'o'   - or any other translation    NUM_OPCODES  = 8,    // Number of operations in malbolge}; // True if it's a legal Malbolge operationstatic inline int legal_op(unsigned int op){    switch(op) {     case OP_READ_DATA:    case OP_READ_IP:    case OP_ROT_RIGHT:    case OP_TERNARY:    case OP_WRITE:    case OP_READ:    case OP_TERMINATE:    case OP_NOP:    return 1;     }    return 0; }// Decrypt/decode the contenct in the memory as a malbolge operation.// The pos/addr in memory is a necessary part of the operation. static inline unsigned short decode_op(unsigned short val, unsigned short pos){    return (val - 33 + pos) % 94; }// Given a legal opcode, encode it such that decode_op brings back the original opcode. static inline unsigned short encode_op(unsigned short opcode, unsigned short pos){    // Need to convert to ints to get correct treatment of the expression using modulo arithmetic.     int o = opcode;     int p = pos;     return 33 + imod(o - p, 94);}// Used by malbolge to modify the instruction the IP(c) is currently pointing at. static const char xlat2[] =  "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72FhOA1C"  "B6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";// Perform a tritwise op on the values x and ystatic inline unsigned short op(unsigned short x, unsigned short y){    unsigned short i = 0, j;    static const unsigned short p9[5] =    { 1, 9, 81, 729, 6561 };  // Tritvals :  1=3**0, 9=3**2, 81=3**4, 729=3**6, 6561=3**8    static const unsigned short o[9][9] =    {        { 4, 3, 3, 1, 0, 0, 1, 0, 0 },        { 4, 3, 5, 1, 0, 2, 1, 0, 2 },        { 5, 5, 4, 2, 2, 1, 2, 2, 1 },        { 4, 3, 3, 1, 0, 0, 7, 6, 6 },        { 4, 3, 5, 1, 0, 2, 7, 6, 8 },        { 5, 5, 4, 2, 2, 1, 8, 8, 7 },        { 7, 6, 6, 7, 6, 6, 4, 3, 3 },        { 7, 6, 8, 7, 6, 8, 4, 3, 5 },        { 8, 8, 7, 8, 8, 7, 5, 5, 4 },    };    for (j = 0; j < 5; j++)    i += o [y / p9[j] % 9] [x / p9[j] % 9] * p9[j];    return (i);}/* ------------------------------------------------------------ */ /* I'm using an STL map to implement a sparse array. This gives me a * 10-fold increase in total execution speed speed from saving memory * bandwidth when I push and pop copies of the MBSearch object on the * stack. */ typedef std::map<unsigned int,unsigned int> MBMemory; class MBSearch {public:    unsigned short Ra, Rc, Rd;        // Registers    int   nFetches;                   // Number of new fetches (that caused a branch in the search algorithm)    int   curNewMem;                  // current position we had to create a new memory op at     int   curNewOP;                   // which of the opcodes did we currently write    int   odepth;                     // current depth / number of new instructions since last output        MBMemory mem;                     // Current content     MBMemory orig;                    // The program value we wrote when a read fault was triggered    int highestAddrRead;              // Highest address read    InterpreterStage iStage;          // Current stage of the interpreter    unsigned short instr;             // used internally in the loop, currently read instruction    std::string output;     // Return values from doExec    enum {    RES_OK,     RES_INFINITE_LOOP,    RES_TRIED_INPUT,    RES_MAX_ITERS,    RES_WRITE_MISMATCH,    RES_ERROR,    RES_BRANCH_DEPTH,    };     void initExec();    int doExec();     // read and write functions for the interpreters memory    unsigned short getMem(unsigned short addr);     unsigned short storeMem(unsigned short addr, unsigned short val);         // Insert a decoded program (simplifies auto-generating malbolge programs)    int insertDecodedProg(unsigned short *prog, int len);    // Highest memory address that was accessed by the program. No need to store anything after this    int maxMemLoc() { return highestAddrRead; }        // Dump the current program to a given file, inserting NOPs in memory locations that     // were not visited.    void dumpProgram(std::string fname); }; // MBSearch objects are pushed and popped from this stack to implement recursive execution path searchesstd::stack<MBSearch*> globalStack; /* This is a list of the sequence of Malbolge opcodes that we try in the searching interpreter.  * NB: the WRITE (=print) operation is put first, to favorise program output. In my limited testing, this  * has resulted in finding the targets faster.  */ unsigned short MalbolgeOps[] = {    OP_WRITE, // nb    OP_READ_DATA,     OP_READ_IP,    OP_ROT_RIGHT,    OP_TERNARY,    OP_READ,    OP_TERMINATE,    OP_NOP};/* ------------------------------------------------------------ */ /*  * Retrieves from the memory, generating a branch exception every time a new  * location is visited.  */ unsigned short MBSearch::getMem(unsigned short addr){    if (addr >= MAX_TRIT)    {     //std::cerr << "MBSearch::getMem called with addr " << addr << " with is outside legal bounds\n";    throw ILLEGAL_ADDR_EXCEPTION; // program made an illegal reference, which will not fare well with the original interpreter, so abort this branch    }    if (addr >= maxAllowedProgLen)     throw MAX_APLEN_EXCEPTION;        if (addr > highestAddrRead)    highestAddrRead = addr;         MBMemory::iterator pos = mem.find(addr);     if (pos != mem.end())    return pos->second;  // already have it    // Reading a new memory location that has never been visited before.     // First, check whether we have branched out too deeply before omitting chars    ++odepth;     if (odepth > MAX_OSEARCH)    throw BRANCH_DEPTH_EXCEPTION;     // Simply fill in the first possible OP, then store this object on the stack, allowing the main loop to     // pick it up again and modify it later (restarting the object with the next possible instruction).     curNewMem = addr;         // keep track of addr, so main loop can modify this instruction    curNewOP  = 0;            // we're currently using the first one    orig[addr] = mem[addr]  = encode_op(MalbolgeOps[curNewOP], addr);    ++nFetches;    // Store a copy of this one on the stack    globalStack.push(new MBSearch(*this));     // default copy constructor is ok    return mem[addr];}unsigned short MBSearch::storeMem(unsigned short addr, unsigned short val){    // NB: writes to an addr always occurs after a read to the same addr, so we never have to consider path branching     // or any other recording here.     if (addr >= MAX_TRIT)    {     std::cerr << "MBSearch::storeMem called with addr " << addr << " with is outside legal bounds\n";    throw ILLEGAL_ADDR_EXCEPTION; // program made an illegal reference, which will not fare well with the original interpreter, so abort this branch    }    if (addr >= maxAllowedProgLen)     throw MAX_APLEN_EXCEPTION;    mem[addr] = val;    return 0; }int MBSearch::doExec(){    const long long MAX_ITERS = 100000000LL;     long long iters;     try    {     for (iters = 0; iters < MAX_ITERS; iters++) // Guard againt infinite loops    {         switch(iStage) {         case STAGE_IFETCH:    // instruction fetch         instr = getMem(Rc);         // Check for infinity: trying to execute values outside the 94-range causes an infinite loop!        if (instr < 33 || instr > 126)             return RES_INFINITE_LOOP;         break;         case STAGE_EXEC:      // execute given instruction        // Decode op to NOP or one of the 8 ops.         switch (decode_op(instr, Rc))        {        case OP_READ_DATA:  // read data register from current             Rd = getMem(Rd);            break;        case OP_READ_IP:  // jump to addr             Rc = getMem(Rd);            break;        case OP_ROT_RIGHT:  // rotate right 1, lstrit=> mstrit (3**9 = 19683)        {            unsigned short t = getMem(Rd);             Ra = t / 3 + t % 3 * 19683;            storeMem(Rd, Ra);            break;         }        case OP_TERNARY:  // run ternary operator on two values            Ra = op(Ra, getMem(Rd));            storeMem(Rd, Ra);            break;        case OP_WRITE:  // output accumulator as a character        {            // Checks whether this is a 'good' character, otherwise abort!            odepth = 0;             char c = (char) Ra;             if ((output.length() >= TARGET.length()) ||  // too long string            (c != TARGET[output.length()]))          // wrong character            return RES_WRITE_MISMATCH;             output += c;             break;        }        case OP_READ:  // We don't allow input from stdin in the program            return RES_TRIED_INPUT;         case OP_TERMINATE:  // terminate program            return RES_OK;        case OP_NOP:        default: // Unspecified operatins correspond to NOPs in the original interpreter            break;          }        break;         case STAGE_MODMEM:   { // modify location of memory that the Rc register currently points at        // Modify op at position. Note that all chars in xlat2 are in the legal range for ops: 33..126        // So, an OP will always be translated into an OP (either a NOP or the other 8 ops)        int addr = getMem(Rc);         if (addr < 33 || (addr > (95+33)))        {             // Pruning search paths that result in accesses out of bounds for xlat2            // NB: This happens very often when we search for programs, so we need to explicitly prune these            // paths as they will not execute correctly if we try them with the interpreter.            return RES_ERROR;         }        storeMem(Rc, xlat2[addr - 33]);            break;         }        case STAGE_MODINC:    // modulo increment instruction and data pointer        Rc = modInc(Rc, MAX_TRIT);         Rd = modInc(Rd, MAX_TRIT);         break;         default:        std::cerr << "ERROR, interpreter interpreter with illegal stage " << iStage << std::endl;         exit(-1);        }         iStage = (InterpreterStage) modInc(iStage, STAGE_NUMSTAGES);     }    }    catch (MB_Exception e)    {    switch (e) {     case BRANCH_DEPTH_EXCEPTION:    case MAX_APLEN_EXCEPTION:        return RES_BRANCH_DEPTH;    default:        return RES_ERROR;    }    }    return RES_MAX_ITERS;}void MBSearch::initExec(){    Ra = 0;    Rc = 0;     Rd = 0;     output = "";     odepth = 0;     iStage = STAGE_IFETCH; }void MBSearch::dumpProgram(std::string fname){    std::ofstream f(fname.c_str(), std::ios::trunc);     for (int i = 0; i <= highestAddrRead; i++)     {    MBMemory::iterator pos = mem.find(i);     if (pos == mem.end())        f << (char) (encode_op(OP_NOP, i));   // Since these aren't fetched, I could dump anything here    else        f << (char) orig[i];     }}/* ------------------------------------------------------------ */ void printCurOutput(MBSearch *cur, int newline = true){    std::cout << "\r   output from program '" << cur->output << "' "          << "maxMemLoc " << cur->maxMemLoc()           << " nFetches " << cur->nFetches << "                     ";     if (newline)    std::cout << std::endl;}      /* Dumps a program to a filename made from the prefix, the length of the program and the suffix .mb */void storeProgram(std::string prefix, MBSearch * prog) {    std::ostringstream str;     str << prefix << prog->maxMemLoc() << ".mb";    prog->dumpProgram(str.str());}int main(int argc, char *argv[]) {    MBSearch *mb = new MBSearch();    mb->initExec();    mb->doExec(); // get the initial execution started.. TODO: this is wrong. I'm ignoring the result of the first path, even if it could be correct (however unlikely)    MBSearch *bestProg = NULL;     std::cout << "Parameters for the generator\n";     std::cout << "    TARGET             '" << TARGET << "'\n";    std::cout << "    MAX_OSEARCH        " << MAX_OSEARCH << std::endl;     std::cout << "    MAX_SEARCH_ITERS   " << MAX_SEARCH_ITERS << std::endl;     std::cout << "    maxAllowedProgLen  " << maxAllowedProgLen << std::endl;    std::cout << "    sizeof(MBSearch)   " << sizeof(MBSearch) << std::endl;     std::cout << "    sizeof(xlat2)      " << sizeof(xlat2) << std::endl;         long long start = get_tod_usecs();    // start of search    long long prevOut = start;            // previous output time    for (int i = 0; i < MAX_SEARCH_ITERS && !globalStack.empty(); i++)    {     MBSearch *cur = globalStack.top();    globalStack.pop();    if (bestProg != NULL && cur->maxMemLoc() >= bestProg->maxMemLoc())    {        // No point in ********** along a longer code path.         delete cur;         continue;     }        ++cur->curNewOP;     if (cur->curNewOP >= NUM_OPCODES)    {         // exchausted our options with this branch        delete cur;         continue;     }    // First, modify the current instruction    int addr = cur->curNewMem;    cur->orig[addr] = cur->mem[addr] = encode_op(MalbolgeOps[cur->curNewOP], addr);    // prepare for next round, push a copy back on the stack before we execute with the current search path    globalStack.push(new MBSearch(*cur));    int ret = cur->doExec();    if (i % 50000 == 0)    {         // every once in a while, provide some output for the user        std::cout << "\n   done with search # " << i << " DT " << timeSince(prevOut) << std::endl;        printCurOutput(cur);         prevOut = get_tod_usecs();     }    if (ret == MBSearch::RES_OK && cur->output.compare(TARGET) == 0)    {         // Found a correct program that terminates after printing the target string.        // Check if it's better than the currently best program, and store the result        if ((bestProg == NULL) || (cur->maxMemLoc() < bestProg->maxMemLoc()))        {         if (bestProg)            delete bestProg;         bestProg = new MBSearch(*cur);         std::cout << "\nSTORING new best program with score " << bestProg->maxMemLoc()              << " after " << timeSince(start) << " seconds" << std::endl;         printCurOutput(cur);         storeProgram("/tmp/t-", bestProg);         maxAllowedProgLen = bestProg->maxMemLoc();        }    }    delete cur;     };    return 0; }
Ошибки:
D:\mbolge-gen\ggg\mbolge-gen.cpp In function `long long unsigned int get_tod_usecs()': 70 D:\mbolge-gen\ggg\mbolge-gen.cpp aggregate `timeval tod' has incomplete type and cannot be defined 71 D:\mbolge-gen\ggg\mbolge-gen.cpp `gettimeofday' undeclared (first use this function) 
Подскажите что делать? И нечего что я utils.h интегрировал в cpp файл ? так меньше ошибок     


Может я писсимист, но исходники вроде как под gcc заточены, есть высокая вероятность того, что для того чтобы их скомпилить придется кое-где и кое-что переписать. Кстати msvc понимает AT&T синтакс ассемблера ?


А в линухе это можно скомпилить?З.Ы. /me пошел ставить линух...


А в линухе это можно скомпилить?З.Ы. /me пошел ставить линух...
А mingw не справится ?---Не смотря на ошибку все собралось
c++ -Wall -O2 -g  -o mbolge-gen mbolge-gen.cpp  -staticcc -Wall -O2 -g  -o interp-orig interp-orig.c -staticprocess_begin: CreateProcess((null), cc -Wall -O2 -g -o interp-orig interp-orig.c -static, ...) failed.make (e=2): ═х єфрхЄё  эрщЄш єърчрээ√щ Їрщы.make: *** [interp-orig] Error 2
И даже работает:
Parameters for the generator    TARGET             'Hello world'    MAX_OSEARCH        10    MAX_SEARCH_ITERS   10000000    maxAllowedProgLen  250    sizeof(MBSearch)   88    sizeof(xlat2)      95   done with search # 0 DT 0   output from program '' maxMemLoc 1 nFetches 2   done with search # 50000 DT 3.42192   output from program 'Hello' maxMemLoc 116 nFetches 50   done with search # 100000 DT 3.48442   output from program 'Hello w' maxMemLoc 125 nFetches 70   done with search # 150000 DT 3.29692   output from program 'Hello worl' maxMemLoc 132 nFetches 100STORING new best program with score 135 after 10.4533 seconds   output from program 'Hello world' maxMemLoc 135 nFetches 108STORING new best program with score 134 after 10.5001 seconds   output from program 'Hello world' maxMemLoc 134 nFetches 105STORING new best program with score 132 after 10.8283 seconds   output from program 'Hello world' maxMemLoc 132 nFetches 102   done with search # 200000 DT 4.07818   output from program 'Hello wo' maxMemLoc 130 nFetches 80   done with search # 250000 DT 3.92192   output from program 'Hello wo' maxMemLoc 130 nFetches 80   done with search # 300000 DT 2.82816   output from program 'Hello wo' maxMemLoc 129 nFetches 80   done with search # 350000 DT 2.79691   output from program 'Hello wo' maxMemLoc 129 nFetches 80   done with search # 400000 DT 2.81254   output from program 'Hello wo' maxMemLoc 129 nFetches 80   done with search # 450000 DT 2.85941   output from program 'Hello wo' maxMemLoc 129 nFetches 80   done with search # 500000 DT 5.48445   output from program 'Hello wor' maxMemLoc 129 nFetches 90   done with search # 550000 DT 9.89075   output from program 'Hello wor' maxMemLoc 129 nFetches 90   done with search # 600000 DT 6.17195   output from program 'Hello worl' maxMemLoc 129 nFetches 97


Как вам это удалось ?    у меня на 
- gcc 3.3.1 (20030804-1) (C/C++ only)- binutils 2.14.90 (20030807-1)- mingw runtime 3.2- w32api 2.4- gdb 6.0 (20031011)- gnu make 3.80.0-3
куча ошибок :
C:\MinGWStudio\MinGW\bin>mingw32-make -f makefilec++ -Wall -O2 -g  -o mbolge-gen mbolge-gen.cpp  -staticIn file included from mbolge-gen.cpp:28:utils.h: In function `long long unsigned int get_tod_usecs()':utils.h:38: error: aggregate `timeval tod' has incomplete type and cannot be   definedutils.h:39: error: `gettimeofday' undeclared (first use this function)utils.h:39: error: (Each undeclared identifier is reported only once for each   function it appears in.)mingw32-make: *** [mbolge-gen] Error 1C:\MinGWStudio\MinGW\bin>
если не стерли, прикрепите пожалуйста exe-шник, а то я замучаюсь...