title: Rust and Python on W10: LNK1181
body: <p>I'm trying to write a Rust module which can be called from Python. I'm following this page:</p>
  <p><a href="https://developers.redhat.com/blog/2017/11/16/speed-python-using-rust#edit_src_lib_rs" rel="nofollow noreferrer">https://developers.redhat.com/blog/2017/11/16/speed-python-using-rust#edit_src_lib_rs</a></p>
  <p>On <code>cargo build --release</code> I get this error:</p>
  <blockquote>
  <p>= note: LINK : fatal error LNK1181: cannot open input file
  'python39.lib'</p>
  </blockquote>
  <p>This has come up before, and <a href="https://stackoverflow.com/a/63505627/595305">this</a> seems the most recent and relevant answer.</p>
  <p>I seem to have tried all the possible solutions in that answer, including locating and running vcvars64.bat, as detailed <a href="http://asyncbulbs.blogspot.com/2017/06/workaround-for-rustc-with-new-visual.html" rel="nofollow noreferrer">here</a>. No joy.</p>
  <p>I have MS Visual Studio (2019) installed, with the C++ and W10 SDK components.</p>
  <p>Significantly, <em><strong>this error sometimes does not occur when I don't include the</strong></em> <code>--release</code> <em><strong>switch</strong></em>. Without it, the program (sometimes) compiles and runs OK. Given that one reason for wanting to make a Rust module is performance, however, I'd like to solve this problem. Also I have now found that this successul building of a &quot;debug&quot; build is a) intermittent and b) partial: when it fails, some of the desired output files are created but not others.</p>
  <p>And...</p>
  <p>According to the page at the first link, it seems that after <code>build</code>, I should then be looking for a file ending .so. In a W10 OS I'm looking for a .dll file.</p>
  <p>If it builds completely successfully, under target\debug I have myrustlib.d, myrustlib.dll, myrustlib.dll.exp, myrustlib.dll.lib, myrustlib.pdb, pyext_myrustlib.pdb, pyext_myrustlib.d and pyext_myrustlib.exe. None of these, renamed and/or given an .dll extension as applicable, can be successfully imported as a Python module, at least as documented on that page.</p>
  <p>I've also found <a href="https://codeburst.io/how-to-use-rust-to-extend-python-360174ee5819" rel="nofollow noreferrer">this more recent page</a> for doing the same thing. I get the same 1181 error.</p>
  <p><strong>python39.lib</strong></p>
  <p>I found out where this is located in my system, under ... Python\Python39\libs. I modified my PATH env var to specifically include this path (and rebooted). Still the same error.</p>