Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cl.exe can't find main.cpp when running from wsl location #3118

Closed
karlbenoit opened this issue Apr 22, 2018 · 6 comments
Closed

cl.exe can't find main.cpp when running from wsl location #3118

karlbenoit opened this issue Apr 22, 2018 · 6 comments

Comments

@karlbenoit
Copy link

karlbenoit commented Apr 22, 2018

I just discovered that windows/wsl interoperability is now possible. That's awesome and I tought, maybe I could use wsl instead of cygwin!

So what I'm trying to achieve is to build a windows app using the MSVC toolchain with cmake. I don't actually want to do crosscompiling - i.e. I don't want to use mingw. I want to use wsl as an alternative to cygwin to compile a windows application.

(I read a little on the matter and I found out that there is currently a limitation that might partly explain the issue described below - https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/)

  1. To have the proper environment loaded, launch the MSVC console.
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.6.6
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>
  1. From there, call wsl.exe.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>wsl.exe
me@home:/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community$ cd ~/test
me@home:~/test/$ which cl.exe link.exe rc.exe
/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x86/cl.exe
/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x86/link.exe
/mnt/c/Program Files (x86)/Windows Kits/10/bin/10.0.16299.0/x64/rc.exe
  1. Generate the cmake files using the following command from a build directory:
mkdir -p build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake ..

When I run cmake I get the following error:

-- The CXX compiler identification is unknown
-- Check for working CXX compiler: /mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: /mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x64/cl.exe -- broken
CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler "/mnt/c/Program Files (x86)/Microsoft Visual
  Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x64/cl.exe" is
  not able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/karl/test/build/CMakeFiles/CMakeTmp
...
  1. This is what happens when I try to compile main.cpp without cmake:
me@home:~/test$ ls -la
total 1
drwxrwxrwx 0 karl karl 512 Apr 22 10:15 .
drwxr-xr-x 0 karl karl 512 Apr 22 10:16 ..
-rw-rw-rw- 1 karl karl  48 Apr 22 09:28 CMakeLists.txt
-rw-rw-rw- 1 karl karl  47 Apr 22 09:17 main.cpp
-rw-rw-rw- 1 karl karl 532 Apr 22 09:38 toolchain.cmake
me@home:~/test$ cl.exe main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26131.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
c1xx: fatal error C1083: Cannot open source file: 'main.cpp': No such file or directory

Windows Build Number: Microsoft Windows [Version 10.0.16299.371]

test.tar.gz

@karlbenoit karlbenoit changed the title use wsl as alternative to cygwin cl.exe can't find main.cpp when running from wsl location Apr 22, 2018
@WSLUser
Copy link

WSLUser commented Apr 23, 2018

I believe this is what you're looking for: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/Building%20the%20Extension.md

Might also be relevant: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/Debugger/gdb/Windows%20Subsystem%20for%20Linux.md

File path has changed on FCU from C:\Windows\System32 to C:\Users\username\AppData\Microsoft\WindowsApps\pick a distro

If there's still an issue with your testcase file it at over in https://github.com/Microsoft/vscode-cpptools

@karlbenoit
Copy link
Author

karlbenoit commented Apr 23, 2018

Thanks for your answer DarthSpock. (EDIT: I believe you wanted to answer to this post: #3112 :P)

I'm not quite how this solution addresses the issue though. I'm not using Visual Studio Code, I'm using Visual Studio 2017 Community Edition.

The issue is that the compiler is unable to see the cpp file it's trying to compile because it expects it to be in the CWD which it isn't. This is what happens when I try to compile the file without cmake:

me@home:~/test$ ls -la
total 1
drwxrwxrwx 0 karl karl 512 Apr 22 10:15 .
drwxr-xr-x 0 karl karl 512 Apr 22 10:16 ..
-rw-rw-rw- 1 karl karl  48 Apr 22 09:28 CMakeLists.txt
-rw-rw-rw- 1 karl karl  47 Apr 22 09:17 main.cpp
-rw-rw-rw- 1 karl karl 532 Apr 22 09:38 toolchain.cmake
me@home:~/test$ cl.exe main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26131.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
c1xx: fatal error C1083: Cannot open source file: 'main.cpp': No such file or directory

@WSLUser
Copy link

WSLUser commented Apr 23, 2018

You can file Community Edition over there as well as it uses the same cpp tools. You'll find there's very little difference between the 2 but seeing as I've used VS Code vice Community Edition, I'm not savvy with the specific differences from a technical perspective. As I've said, I recommend filing with the CPP folks. They have plenty of exposure to us WSL folks bugging them for things.

@karlbenoit
Copy link
Author

Aight, I filed the issue there too. Thanks DarthSpock!

@karlbenoit
Copy link
Author

cl.exe works under /mnt/d/ as suggested by @bobbrow

My mistake was to also use wsl's cmake. When using cmake for windows, the project is compiling.

I'm closing this issue.

@paulstelian97
Copy link

Apparently Windows 10 version 19H1 will have an upgrade on WSL to expose the Linux-only files in Windows, using something similar to a network share thingy? That will be a general solution and, once that is fixed, Windows tools will finally be able to work with files within your home directory.

[Sorry for the necro]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants