Search code examples
c++circuitdigital-logic

Making a C17 circuit in C++


I'm trying to simulate a C17 logic circuit in C++ using a Library called LibLCS. Click here to see an example of a digital circuit made with this lib. But isnt working. I cant compile the code and I have no idea why.

#include <lcs/lcs.h>
#include <lcs/nand.h>
#include <lcs/simul.h>
#include <lcs/tester.h>
#include <lcs/changeMonitor.h>

// All libLCS constructs are defined under
// the namespace lcs.

using namespace lcs;


int main()
{
  Bus<1> a, b, c, d, e, ga, gb, gc, gd, ge, gf;

  Nand<2> nandGate1(ga, (a,b)), nandGate2(gb, (b,d));
  Nand<2> nandGate3(gc, (c,gb)), nandGate4(gd, (gb,e));
  Nand<2> nandGate5(ge, (ga,gc)), nandGate6(gf, (gc,gd));


  ChangeMonitor<5> inputMonitor((a,b,c,d,e), "Input", DUMP_ON);
  ChangeMonitor<2> outputMonitor((ge,gf), "Output", DUMP_ON);

  Tester<5> tester((a,b,c,d,e));

  Simulation::setStopTime(4000); // Set the stop time.
  Simulation::start(); // Start the simulation.

  return 0;
}

I got the following compilation error:

g++ -o c17 c17.cpp /tmp/cc5TeFfF.o: In function main':
c17.cpp:(.text+0x50a): undefined reference to lcs::Simulation::setStopTime(unsigned int)'
c17.cpp:(.text+0x50f): undefined reference to lcs::Simulation::start()' /tmp/cc5TeFfF.o: In function lcs::Bus<(1)+(1)> const lcs::Bus<1>::operator,<1>(lcs::Bus<1> const&) const':
c17.cpp(.text._ZNK3lcs3BusILi1EEcmILi1EEEKNS0_IXplT_Li1EEEERKNS0_IXT_EEE[_ZNK3l‌​cs3BusILi1EEcmILi1EEEKNS0_IXplT_Li1EEEERKNS0_IXT_EEE]+0x75): 

And many more...


Solution

  • From your errors trace that you gave us in comments, I may tell you that you forgot to link your program with your lib.

    If your lib is called liblcs.so or liblcs.a, so add this flags to your g++ compilation :

    g++ -o c17 c17.cpp -llcs -L"path to the lib folder"
    

    It should works. Or at least it should solve this problem.