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.
- You need to add flag -llightning to gcc command. - gcc example.c -o example -llightning
- 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
- 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
- Now try to run - ./example
 
    