title: How to use a dynamically linked library from relative path
body: <p>I would like to use a dynamic C library from a go application, I can build the application but the library is not found at runtime.
  Here the structure of my project:</p>
  
  <pre><code>src/ctest/
        |- lib/
        |    |- libmylib.so
        |    |- libmylib.h
        |- main.go
  </code></pre>
  
  <p>in main.go I import the .h and .so files:</p>
  
  <pre><code>/*
  #cgo CFLAGS: -I./lib
  #cgo LDFLAGS: -L./lib -lmylib
  #include &lt;mylib.h&gt;
  */
  import "C"
  
  func main() {
      C.testMyLib()
  }
  </code></pre>
  
  <p>I can build the application successfully, but when launched it throws this error:</p>
  
  <pre><code>error while loading shared libraries: libmylib.so.0: cannot open shared object file: No such file or directory
  </code></pre>
  
  <p>If I copy the libmylib.so file in /usr/lib then everything works as expected; however, I would like that my application automatically searches  for the needed library in CURRENT_PATH/lib at runtime without setting environment variables. How can I achieve it?</p>