Search code examples
verilogsimulationverilator

Verilator, running simulator gives: Invalid argument


I'm following this tutorial. On page 24 I don't get the Makefile the tutorial talks about. When I run ./thruwire it says: bash: ./thruwire: Invalid argument.

This is my thruwire.v:

module thruwire(i_sw, o_led);
    input   wire    i_sw;
    output  wire    o_led;
    
    assign o_led = i_sw;
endmodule

After having generated this verilog file I ran these commands to create the obj_dir directory:

verilator -Wall -cc thruwire.v
cd obj_dir
make -f Vthruwire.mk

I then created a file thruwire.cpp in my main directory (so the one above obj_dir) that looks like this:

#include <stdio.h>
#include <stdlib.h>
#include "Vthruwire.h"
#include "verilated.h"

int main(int argc, char **argv)
{
    Verilated::commandArgs(argc, argv);
    
    Vthruwire *tb = new Vthruwire;
    
    for(int k = 0; k < 20; k++)
    {
        tb->i_sw = k&1;
        
        tb->eval();
        
        printf("k = %2d, ", k);
        printf("i_sw = %2d, ", tb->i_sw);
        printf("led = %2d, ", tb->o_led);
    }
}

I went back one directory and compiled everything like this:

cd ..
g++ -I /usr/share/verilator/include -I obj_dir /usr/share/verilator/include/verilated.cpp thruwire.cpp obj_dir/Vthruwire__ALL.a -o thruwire

By now, I've done everything that the tutorial says up till slide 24. However, there is no Makefile in my project directory, as should be the case according to the tutorial. When I run ./thruwire I get said error.

I'm new to all this, please help me out. Am I missing something?

I tried using the --exe flag, since the documentation says a simulation executable will be generated for me. But it gives me the same error upon running. I tried specifying arguments myself and removing the arguments from the main function alltogether but it keeps giving me that error.

I'm running the simulation in a virtual box image. I recently shrunk the .vdi using this guide. I don't know if that could have anything to do with it.


Solution

  • My toolbox was broken. A working toolbox does not give these errors as has been discussed in the comments (unfortunately the user deleted them). I guess trying to build the whole toolsuite yourself is not a good idea unless you really know what you are doing. I found a cad suite that can be readily used without problems. It has all the needed tools precompiled and working.