title: Creating and linking static rust library and link to c
body: <p>I tried to create a rust library that is callable by a c program, so far i managed to create a dynamic library and call it (library created using <code>rustc --crate-type=cdylib src/lib.rs -o libCustomlib.so</code>, linked using <code>gcc main.o -lCustomlib</code>).</p>
  <p>When i now take the same code but compile it as a static library (<code>rustc --crate-type=staticlib src/lib.rs -o libCustomlib.a</code>) gcc throws errors when linking (using <code>gcc main.o -L. -l:libCustomlib.a</code>)</p>
  <p>the errors are all undefined references to various functions</p>
  <p>first few lines:</p>
  <pre><code>/usr/bin/ld: ./libCustomlib.a(std-b1b61f01951b016b.std.5rqysbiy-cgu.2.rcgu.o): in function `std::sys::unix::mutex::Mutex::init':
  /usr/src/rustc-1.43.0//src/libstd/sys/unix/mutex.rs:46: undefined reference to `pthread_mutexattr_init'
  /usr/bin/ld: /usr/src/rustc-1.43.0//src/libstd/sys/unix/mutex.rs:48: undefined reference to `pthread_mutexattr_settype' 
  /usr/bin/ld: /usr/src/rustc-1.43.0//src/libstd/sys/unix/mutex.rs:52: undefined reference to `pthread_mutexattr_destroy' 
  </code></pre>
  <p>full error is over 100 lines long but the lines are all of this form</p>
  <p>the lib.rs currently only has one test helloWorld function:</p>
  <pre class="lang-rust prettyprint-override"><code>#[no_mangle]
  pub extern &quot;C&quot; fn fn_test() {
      println!(&quot;Hello, world!&quot;);
  }       
  </code></pre>
  <p>with the header file included in the caller part being:</p>
  <pre><code>extern void fn_test();
  </code></pre>
  <p>The question is, is my error at creating the static library or at linking it? Or lies the problem somewhere else and it should not work with static libraries? Should i just use the dynamic approach (which i would like to avoid since static ones feel more like using multiple languages in one exe since you don't have to distribute the library)?</p>
  <p>(disclaimer: for everyone asking why i would do something like that without a good reason: it's a fun project, the entire program should be as overcomplicated as possible and that's the reason why i want to use different languages)</p>