title: undefined reference to `readline'
body: <p>I'm having a problem trying to run the <a href="http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html" rel="noreferrer">GNU Readline</a> library sample code <a href="https://en.wikipedia.org/wiki/GNU_readline#Sample_code" rel="noreferrer">available in wikipedia</a>. Here it goes:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;readline/readline.h&gt;
  #include &lt;readline/history.h&gt;
  
  int main()
  {
      char* input, shell_prompt[100];
  
      // Configure readline to auto-complete paths when the tab key is hit.
      rl_bind_key('\t', rl_complete);
  
      for(;;) {
          // Create prompt string from user name and current working directory.
          snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
  
          // Display prompt and read input (n.b. input must be freed after use)...
          input = readline(shell_prompt);
  
          // Check for EOF.
          if (!input)
              break;
  
          // Add input to history.
          add_history(input);
  
          // Do stuff...
  
          // Free input.
          free(input);
      }
  }
  </code></pre>
  
  <p>I'm working on a restricted environment were readline was not available, so I had to download the sources, compile it and install it to my home dir.</p>
  
  <p>This is the structure inside my home directory:</p>
  
  <pre><code>.local
  ├── include
  │   └── readline
  │       ├── chardefs.h
  │       ├── history.h
  │       ├── keymaps.h
  │       ├── readline.h
  │       ├── rlconf.h
  │       ├── rlstdc.h
  │       ├── rltypedefs.h
  │       └── tilde.h
  └── lib
      ├── libhistory.a
      ├── libhistory.so -&gt; libhistory.so.6
      ├── libhistory.so.6 -&gt; libhistory.so.6.2
      ├── libhistory.so.6.2
      ├── libreadline.a
      ├── libreadline.so -&gt; libreadline.so.6
      ├── libreadline.so.6 -&gt; libreadline.so.6.2
      └── libreadline.so.6.2
  </code></pre>
  
  <p>The problem is, when I call gcc it throws me an error:</p>
  
  <pre><code>$ gcc hello.c -o hello_c.o -I /home/my-home-dir/.local/include
  /tmp/cckC236E.o: In function `main':
  hello.c:(.text+0xa): undefined reference to `rl_complete'
  hello.c:(.text+0x14): undefined reference to `rl_bind_key'
  hello.c:(.text+0x60): undefined reference to `readline'
  hello.c:(.text+0x77): undefined reference to `add_history'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>There is an answer about this <a href="https://stackoverflow.com/questions/4928203/undefined-reference-to-readline">here</a>, but I'm not using Netbeans and I'm not quite sure how to specify the path to the library on the command line.</p>
  
  <p>I tried to tell the linker where the libraries are, but the result is still the same:</p>
  
  <pre><code>$ gcc hello.c -o hello_c.o -I /home/my-home-dir/.local/include -Xlinker "-L /home/my-home-dir/.local/lib"
  /tmp/cceiePMr.o: In function `main':
  hello.c:(.text+0xa): undefined reference to `rl_complete'
  hello.c:(.text+0x14): undefined reference to `rl_bind_key'
  hello.c:(.text+0x60): undefined reference to `readline'
  hello.c:(.text+0x77): undefined reference to `add_history'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Any ideas what I might be missing here?</p>