title: Where should I place a static library so I can link it with a Rust program?
body: <p>I do not know how to link a C library to Rust. Here's what I have done:</p>
  
  <p>My <strong>lib.rs</strong> file contains</p>
  
  <pre><code>#[link(name = "test")]
  extern {
  </code></pre>
  
  <p>The library is built and has the name <code>libtest.a</code>.</p>
  
  <p>I do not know where to put it. I have tried several places, but I still have errors of this type when doing <code>cargo run</code></p>
  
  <pre class="lang-none prettyprint-override"><code>error: linking with `cc` failed: exit code: 1
  //..
  note: /usr/bin/ld: no se puede encontrar -ltest
  note: /usr/bin/ld: no se puede encontrar -ltest
  note: /usr/bin/ld:.......
  //..
  </code></pre>
  
  <p>Translation of the above <code>/usr/bin/ld: no se puede encontrar -ltest</code> -> <code>usr/bin/ld: cannot find -ltest</code></p>
  
  <p>I do not know where to put <strong>libtest.a</strong> so that <code>/usr/bin/ld</code> can find it. Cargo does not tell me where the library should be in the project.</p>
  
  <p>My <strong>Cargo.toml</strong> contains</p>
  
  <pre><code>[dependencies.test]
  path = "./src/test"
  
  [dependencies]
  bitflags = "0.7"
  libc = "0.2"
  
  [build-dependencies]
  make-cmd = "0.1"
  </code></pre>
  
  <p>After reading <a href="https://doc.rust-lang.org/book/ffi.html" rel="noreferrer">the FFI section of the documentation</a> again, I thought that maybe the error messages from before were because I was looking for a shared library, so I made the following changes:</p>
  
  <pre><code>#[link(name = "test", kind = "static")]
  </code></pre>
  
  <p>After these changes, I still do not know how to indicate where the library is, but the message now tells me this:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: could not find native static library `test`, perhaps an -L flag is missing?
  </code></pre>