0

I'm trying to run GNU Lightning example. It's a library for working with JIT on C language.

The problem is I can't run simple program from the guide. The example contains following code:

#include <stdio.h>
#include <lightning.h>

static jit_state_t *_jit;

typedef int (*pifi)(int);    /* Pointer to Int Function of Int */

int main(int argc, char *argv[])
{
  jit_node_t  *in;
  pifi         incr;

  init_jit(argv[0]);
  _jit = jit_new_state();

  jit_prolog();                    /*      prolog              */
  in = jit_arg();                  /*      in = arg            */
  jit_getarg(JIT_R0, in);          /*      getarg R0           */
  jit_addi(JIT_R0, JIT_R0, 1);     /*      addi   R0, R0, 1    */
  jit_retr(JIT_R0);                /*      retr   R0           */

  incr = jit_emit();
  jit_clear_state();

  /* call the generated code, passing 5 as an argument */
  printf("%d + 1 = %d\n", 5, incr(5));

  jit_destroy_state();
  finish_jit();
  return 0;
}

Essentially, the guide doesn't describe how I can run the program. There is only a paragraph Configuring and installing GNU lightning.

First, I download the latest version lightning-2.1.2.tar.gz and extracted files.

Then I did the following:

sudo ./configure
sudo make install

But what do I do next? I tried run this as usual:

gcc example.c -o example

And got errors:

/tmp/ccG9QZg8.o: In function `main':
b.c:(.text+0x1a): undefined reference to `init_jit'
b.c:(.text+0x1f): undefined reference to `jit_new_state'
b.c:(.text+0x35): undefined reference to `_jit_prolog'
b.c:(.text+0x44): undefined reference to `_jit_arg'
b.c:(.text+0x60): undefined reference to `_jit_getarg_l'
b.c:(.text+0x84): undefined reference to `_jit_new_node_www'
b.c:(.text+0x98): undefined reference to `_jit_retr'
b.c:(.text+0xa7): undefined reference to `_jit_emit'
b.c:(.text+0xba): undefined reference to `_jit_clear_state'
b.c:(.text+0xea): undefined reference to `_jit_destroy_state'
b.c:(.text+0xef): undefined reference to `finish_jit'
collect2: error: ld returned 1 exit status

I think I need to add some flag for gcc command or maybe use another command to run this code.

Any ideas?

Update

I solved it.

  1. You need to add flag -llightning to gcc command.

    gcc example.c -o example -llightning
    
  2. If you try to run ./example you'll get an error.

    ./example: error while loading shared libraries: liblightning.so.1: cannot open shared object file: No such file or directory
    
  3. You need to change LD_LIBRARY_PATH.

    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/[path to library]/lightning-2.1.2/lib/.libs/
    
    export LD_LIBRARY_PATH
    
  4. Now try to run

    ./example
    
halfer
  • 19,824
  • 17
  • 99
  • 186
pyloolex
  • 182
  • 1
  • 7
  • 1
    BTW, `gcc example.c -o example` is not you running the program, merely compiling and generating the binary. – Sourav Ghosh Dec 21 '17 at 09:13
  • Yeah, I know. I can run ./example if the compilation is done, but it isn't. – pyloolex Dec 21 '17 at 09:16
  • It is a duplicate, but perhaps you don't recognize it. BTW, look also into [GCCJIT](https://gcc.gnu.org/onlinedocs/jit/), a JITing library above GCC which can generate faster machine code than GNU lightning – Basile Starynkevitch Dec 21 '17 at 10:33

0 Answers0