0

I'm building a cmake/ninja/clang-cl application with Visual Studio and it builds properly when I Generate Cache and Build All.

I can then open Visual Studio's powershell and run ninja clean in the .../out/build/x64-Release directory and re-build with Ctrl-Shift-B. It works fine.

However, when I run ninja clean and then ninja -v in the terminal, it doesn't work. I get a link error:

lld-link: error: could not open 'msvcrt.lib': no such file or directory
lld-link: error: could not open 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcprt.lib': no such file or directory
lld-link: error: could not open 'msvcprt.lib': no such file or directory
lld-link: error: could not open 'MSVCRT.lib': no such file or directory
lld-link: error: could not open 'OLDNAMES.lib': no such file or directory

I found these libraries here "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\lib\x64" and I added them to my LIB environment variable. I assumed that would work since I had the same issue with not linking to kernel32.lib and got it working by adding "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64" to LIB. But it didn't.

My question: Is ninja -v the command executed by Visual Studio upon "Build All"? If so, why would Build All work, but the command ninja -v from VS's powershell fail? If not, how can I tell what command Visual Studio is actually using (so I can replicate it)?

All I want is to build from emacs instead of Visual Studio, so I need a command to bind to a key binding; that command would usually be ninja -v.

More info: when I run ninja -v from powershell after a successful Build All, I get ninja: warning: bad deps log signature or version; starting over

polortiz40
  • 391
  • 4
  • 13
  • 1
    You probably need to source the `vcvars` file first to set up some environment variables. [Visual Studio 2019: build C++ from command line with vcvars64.bat doesn't work anymore](https://stackoverflow.com/questions/59670197/visual-studio-2019-build-c-from-command-line-with-vcvars64-bat-doesnt-work-a) – Botje Jun 15 '20 at 09:45
  • As an alternative to Ninja, you can try the `cmake --build` mode, I don't know if that needs the environment variables as well. – Botje Jun 15 '20 at 09:46
  • Oh this might work.. So vcvars defines some additional environment variables that Visual Studio is using? Interesting – polortiz40 Jun 15 '20 at 20:28
  • cmake --build . also seems to fail (I thought this was just another way of invoking 'ninja'?) – polortiz40 Jun 15 '20 at 20:31
  • 1
    Yes, the vcvars batch file sets up the environment. Try starting a "visual studio development shell" and check the environment – Botje Jun 16 '20 at 06:09

0 Answers0