Cannot find module '\\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js' - windows-subsystem-for-linux

My question is related to In WSL2: Ubuntu 20.04 for Windows 10 nodejs is installed but npm is not working
I faced the same problem, which I resolved by converting the line endings to Unix style. But then, running the command starts failing with this:
mark#L-R910LPKW:~$ npm -v
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module '\\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
mark#L-R910LPKW:~$
Which surfaces an interesting file path - \\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
So \\wsl.localhost\Ubuntu-20.04 actually references the root of the Linux distro when examined from Windows:
C:\> dir \\wsl.localhost\Ubuntu-20.04
Directory: \\wsl.localhost\Ubuntu-20.04
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/6/2022 6:27 PM home
d----- 4/23/2020 2:40 AM srv
d----- 10/7/2022 3:18 PM .certs
d----- 10/7/2022 4:41 PM etc
d----- 4/23/2020 2:40 AM opt
d----- 10/7/2022 4:41 PM root
d----- 10/6/2022 6:27 PM mnt
d----- 4/23/2020 2:41 AM usr
d----- 4/23/2020 2:40 AM media
d----- 10/6/2022 10:21 PM sys
d----- 10/6/2022 10:21 PM dev
d----- 4/23/2020 2:49 AM boot
d----- 10/6/2022 10:27 PM run
d----- 10/6/2022 10:21 PM proc
d----- 4/10/2020 10:57 AM snap
d----- 10/7/2022 3:50 PM tmp
d----- 4/23/2020 2:43 AM var
d----- 4/10/2019 12:35 PM lost+found
-----l 4/23/2020 2:40 AM 7 lib
-----l 4/23/2020 2:40 AM 9 lib64
-----l 4/23/2020 2:40 AM 8 sbin
-----l 4/23/2020 2:40 AM 7 bin
-----l 4/23/2020 2:40 AM 9 lib32
-----l 4/23/2020 2:40 AM 10 libx32
------ 6/18/2022 4:36 AM 1392928 init
C:\>
And /mnt/c is where the C: drive is mounted under Linux:
mark#L-R910LPKW:~$ ls /mnt/c
ls: cannot access '/mnt/c/DumpStack.log.tmp': Permission denied
ls: cannot access '/mnt/c/hiberfil.sys': Permission denied
ls: cannot access '/mnt/c/pagefile.sys': Permission denied
ls: cannot access '/mnt/c/swapfile.sys': Permission denied
'$Recycle.Bin' DumpStack.log 'Program Files (x86)' Users log
'$WINRE_BACKUP_PARTITION.MARKER' DumpStack.log.tmp ProgramData Windows node-modules-cache
'$WinREAgent' Graphviz Recovery cygwin pagefile.sys
'Ceridian Software' ILSpy Shared cygwin64 swapfile.sys
Config.Msi Intel Symbols dayforce tenorshare
DBBackups NDepend 'System Volume Information' docker totalcmd
DRIVERS PerfLogs Temp hiberfil.sys utils
'Documents and Settings' 'Program Files' Ubuntu lfs work
mark#L-R910LPKW:~$
So \\wsl.localhost\Ubuntu-20.04\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js is essentially C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js, which definitely exists:
C:\> dir "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
Directory: C:\Program Files\nodejs\node_modules\npm\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/6/2021 3:07 PM 4861 npm-cli.js
C:\>
However, there is a disconnect - the directory \\wsl.localhost\Ubuntu-20.04\mnt\c is inaccessible from Windows:
C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt
Directory: \\wsl.localhost\Ubuntu-20.04\mnt
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/6/2022 10:21 PM wsl
d----- 10/7/2022 4:28 PM wslg
d----- 10/7/2022 7:19 AM c
C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt\c
dir : Access is denied
At line:1 char:1
+ dir \\wsl.localhost\Ubuntu-20.04\mnt\c
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (\\wsl.localhost\Ubuntu-20.04\mnt\c:String) [Get-ChildItem], Unauthor
izedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
C:\>
But the other directories are accessible:
C:\> dir \\wsl.localhost\Ubuntu-20.04\mnt\wsl\
Directory: \\wsl.localhost\Ubuntu-20.04\mnt\wsl
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/6/2022 10:21 PM docker-desktop-bind-mounts
d----- 10/6/2022 10:21 PM docker-desktop
d----- 10/6/2022 10:21 PM docker-desktop-data
------ 10/6/2022 11:47 PM 122 resolv.conf
C:\>
The difference, as I see it, is that /mnt/c (and everything under it) is owned by my local Linux account whereas the others are owned by the root:
mark#L-R910LPKW:/mnt$ ls -l
total 0
drwxrwxrwx 1 mark mark 4096 Oct 7 07:19 c
drwxrwxrwt 5 root root 120 Oct 6 22:21 wsl
drwxrwxrwt 6 root root 260 Oct 7 16:28 wslg
mark#L-R910LPKW:/mnt$
I wonder if this is the real root cause and if so - what is the proper way to fix it assuming I want this particular path to be accessible from Windows.
I may remove the Windows paths from the Linux PATH entirely, but I want to learn how this stuff works and so it is important to me to understand what is going on and how to fix it.

Related

CMake INSTALL and RENAME cannot find file

I'm trying to make and install a config.cmake file for the project that I'm building, and the install part isn't working because apparently it can't find the file. I was originally using the INSTALL command from cmake, and when that didn't work I tried file( RENAME ... ) because I have a little more experience with it - neither seem to work. I've verified that the file is being made in the correct location and with the expected filename.
This is the relevant part of the CMakeLists.txt:
################################################################################
# Build the config.cmake file for finding project information
################################################################################
file(WRITE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake "set(${PROJECT_NAME}_PROTO_DIR ${PROTO_MAIN_DIR})\n")
file(APPEND ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake "set(${PROJECT_NAME}_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/;${PROTO_GEN_DIR})\n")
file(APPEND ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake "set(${PROJECT_NAME}_LIBRARY_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/)\n")
file(APPEND ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake "set(${PROJECT_NAME}_LIBRARIES ${PROJECT_LIBRARIES})\n")
message( "CMAKE_BINARY_DIR: " ${CMAKE_BINARY_DIR} )
message( "PROJECT_NAME: " ${PROJECT_NAME} )
#INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ~/CMake/Modules/)
file(RENAME ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake ~/CMake/Modules/${PROJECT_NAME}Config.cmake)
Here's the relevant output when I try to rune cmake:
CMAKE_BINARY_DIR: /home/ava/workspace/frontseat_drivers/build
PROJECT_NAME: frontseat
CMake Error at src/frontseat/CMakeLists.txt:47 (file):
file RENAME failed to rename
/home/ava/workspace/frontseat_drivers/build/frontseatConfig.cmake
to
~/CMake/Modules/frontseatConfig.cmake
because: No such file or directory
and here's output confirming that the file is where I expect with the name that I expect:
ava#3b97b310abf0:~/workspace/frontseat_drivers/build$ ls -l
total 32
-rw-rw-r--. 1 ava ava 12219 Jun 13 19:04 CMakeCache.txt
drwxrwxr-x. 5 ava ava 4096 Jun 13 18:48 CMakeFiles
-rw-rw-r--. 1 ava ava 2250 Jun 13 15:41 cmake_install.cmake
-rw-rw-r--. 1 ava ava 315 Jun 14 12:30 frontseatConfig.cmake
-rw-rw-r--. 1 ava ava 6397 Jun 13 18:48 Makefile
drwxrwxr-x. 5 ava ava 98 Jun 13 18:48 src
What would cause CMake not to be able to see the file?
The error is probably about destination file ~/CMake/Modules/frontseatConfig.cmake. It is because CMake doesn't interpret ~ part, so it cannot resolve the path correctly.
Instead of ~ use $ENV{HOME} for point to the user's home directory.

Unable to start Selenium server using WebdriverIO on Windows

I'm following instructions from http://webdriver.io/guide.html
The fourth step mentions this:
java -jar -Dwebdriver.gecko.driver=./geckodriver selenium-server-standalone-3.5.3.jar
After downloading and installing Selenium and WebdriverIO for Windows, I provided the environmental path for all the drivers and executables in System Properties.
I seem to be hitting this issue after I try to execute the aforementioned command through Powershell.
PS C:\webdriverio-test> java -jar -Dwebdriver.gecko.driver=".\geckodriver.exe" .\selenium-server-standalone-3.12.0.jar
Error: Unable to access jarfile .gecko.driver=.\geckodriver.exe
PS C:\webdriverio-test> java -jar -Dwebdriver.gecko.driver=geckodriver.exe .\selenium-server-standalone-3.12.0.jar
Error: Unable to access jarfile .gecko.driver=geckodriver.exe
PS C:\webdriverio-test> java -jar -Dwebdriver.gecko.driver=geckodriver .\selenium-server-standalone-3.12.0.jar
Error: Unable to access jarfile .gecko.driver=geckodriver
PS C:\webdriverio-test> java -jar -Dwebdriver.gecko.driver=./geckodriver .\selenium-server-standalone-3.12.0.jar
Error: Unable to access jarfile .gecko.driver=./geckodriver
If I try running standalone Selenium server without using geckodriver, it works well. However, the main intention is to make it work using geckodriver and something seems to be going wrong here.
It just worked once when I installed it yesterday, but it doesn't seem to be working now. Any pointers as to how to make this work, would be appreciable.
Contents of the directory:
PS C:\webdriverio-test> ls
Directory: C:\webdriverio-test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/31/2018 2:41 PM node_modules
d----- 5/31/2018 10:54 AM nssm-2.24
d----- 5/31/2018 10:40 AM test
-a---- 4/8/2018 12:49 PM 9684296 geckodriver.exe
-a---- 5/31/2018 2:41 PM 50430 package-lock.json
-a---- 5/30/2018 3:37 PM 23556263 selenium-server-standalone-3.12.0.jar
-a---- 5/30/2018 4:16 PM 383 test.js
-a---- 5/31/2018 9:31 AM 471 test_2.js
-a---- 5/31/2018 10:51 AM 9875 wdio.conf.js
Thanks in advance.
The jar file must follow the -jar, noting allowed to insert between -jar and the jar file
Execute in Windows CMD:
java -Dwebdriver.gecko.driver=./geckodriver.exe -jar ./selenium-server-standalone-3.12.0.jar
Execute in Windows PowerShell:
java "-Dwebdriver.chrome.driver=chromedriver_2.38.exe" -jar .\selenium-server-standalone-3.12.0.jar
For PowerShell, if the name of -Dname=value includes ., you must use double quote to around the -Dname=value
Note: please use JDK 8 or above.

CMake shared library executable permission missing at install location

Currently I am creating a simple project which will install a utility shared library.
Here's my CMakeLists:
cmake_minimum_required (VERSION 2.6)
project(MathLibs CXX)
add_library (${PROJECT_NAME} SHARED
fact.cpp
fibo.cpp
isPrime.cpp
)
install (TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${PROJECT_NAME}/bin
LIBRARY DESTINATION ${PROJECT_NAME}/lib
ARCHIVE DESTINATION ${PROJECT_NAME}/lib)
Since I do not have root privileges I cannot install the shared library in system lib folder. I override the CMAKE_INSTALL_PREFIX to $HOME/apps.
When I build the shared library it had the executable permissions.
Here's the build folder with the shared library:
-rw-rw-r-- 1 ameya ameya 9714 Jun 18 20:02 CMakeCache.txt
drwxrwxr-x 5 ameya ameya 4096 Jun 18 20:02 CMakeFiles
-rw-rw-r-- 1 ameya ameya 2701 Jun 18 20:02 cmake_install.cmake
-rw-rw-r-- 1 ameya ameya 84 Jun 18 20:02 install_manifest.txt
-rwxrwxr-x 1 ameya ameya 6808 Jun 18 20:02 libMathLibs.so
-rw-rw-r-- 1 ameya ameya 7748 Jun 18 20:02 Makefile
drwxrwxr-x 3 ameya ameya 4096 Jun 18 20:02 test
After installing the executable permissions disappears.
Here's the install folder location:
-rw-r--r-- 1 ameya ameya 6808 Jun 18 20:02 libMathLibs.so
What am I missing in the CMakeLists.txt to correct this?
They said that CMake doesn't set execute permissions on installed library because on Linux libraries don't need to be executable.
As for library's permissions in build tree, these are set not by CMake but by the linker.
If you want executable permissions of installed library for some reason, use PERMISSIONS option in install() command.
After looking for more details online I found this referenced in the CMake bugs report.
The handling of shared library on different systems is different I tried using Ubuntu and a Fedora workstation.
On Ubuntu system the system installed shared libraries do not have the executable bit set, but on the Fedora Workstation the same library had the executable bit set.
One can have look at the ${CMAKE_ROOT}/cmake/Modules/Platform/Linux.cmake,
which has the CMAKE_INSTALL_SO_NO_EXE macro defined(sorry for the typo in my earlier reply).

LLVm clang , Error: Invalid file format (bad magic) with -fprofile-instr-use

Flag "-fprofile-instr-use" generates error given below.
This issue occurs even if we build llvm,clang and compiler-rt using cmake or configure.
Please let me know your inputs to resolve this issue
error: Could not read profile: Invalid file format (bad magic)
Thanks,
Steps to reproduce this issue:
$ clang -O2 -fprofile-instr-generate hello.c -o c1.out
$ ls -rlt
-rw-r--r-- 1 root root 70 Jul 11 10:10 hello.c
-rwxr-xr-x 1 root root 15793 Jul 11 10:10 c1.out
-rw-r--r-- 1 root root 12203204 Jul 11 10:10 gmon.out
$ ./c1.out
Hello world
$ ls -rlt
-rw-r--r-- 1 root root 70 Jul 11 10:10 hello.c
-rwxr-xr-x 1 root root 15793 Jul 11 10:10 c1.out
-rw-r--r-- 1 root root 12203204 Jul 11 10:10 gmon.out
-rw-r--r-- 1 root root 104 Jul 11 10:10 default.profraw
$ clang -O2 -fprofile-instr-use=default.profraw hello.c -o c2.out
error: Could not read profile: Invalid file format (bad magic)
1 error generated.
Clang version (July 10th-2014 build from stage):
$ clang -v
clang version 3.5.0 (llvm.org/git/clang.git 5f9d646cba20f309bb69c6c358996d71912c54cd) (llvm.org/git/llvm.git dc90a3ab8ffc841a442888940635306de6131d2f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Selected multilib: .;#m64
OS: Ubuntu 14.04
LLVM configure: ../llvm/configure --enable-profiling --enable-optimized --enable-shared --disable-debug-runtime --enable-targets=x86
It turns out that step 3 outlined here: http://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation
is required even if you only have 1 output file you are using. "Combine profiles from multiple runs and convert the “raw” profile format to the input expected by clang" makes it sound like you should only do this if you have multiple profiles, but you need to do it unconditionally.

Building hello world at the command line using Cmake and Visual Studio Express 2010

I'm new to CMake. I am trying to build a very simple program (hello world) using Visual Studio 2010 Express. In the Visual Studio 2010 Command Prompt I ran the command:
cmake -g "NMake Makefiles" .
This appeared to work.
C:\Users\david\dev\cmake\hello_world>cmake -g "NMake Makefiles" .
-- Building for: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/david/dev/cmake/hello_world
Next, I tried to run nmake, which produced the following error:
C:\Users\david\dev\cmake\hello_world>nmake
Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop.
I cannot see a Makefile inside the project directory, so I guess that's why it is not working, or perhaps CMake uses a non standard name for Makefile's? I'm unsure. I've pasted the contents of the project directory below.
C:\Users\david\dev\cmake\hello_world>dir
Volume in drive C has no label.
Volume Serial Number is 4000-10E9
Directory of C:\Users\david\dev\cmake\hello_world
08/05/2012 01:38 PM <DIR> .
08/05/2012 01:38 PM <DIR> ..
08/05/2012 01:38 PM 28,584 ALL_BUILD.vcxproj
08/05/2012 01:38 PM 735 ALL_BUILD.vcxproj.filters
08/05/2012 01:38 PM 12,871 CMakeCache.txt
08/05/2012 01:38 PM <DIR> CMakeFiles
08/05/2012 01:34 PM 151 CMakeLists.txt
08/05/2012 01:38 PM 1,514 cmake_install.cmake
08/05/2012 01:38 PM 3,150 hello_world.sln
08/05/2012 01:38 PM 36,618 hello_world.vcxproj
08/05/2012 01:38 PM 671 hello_world.vcxproj.filters
08/05/2012 01:37 PM 2,213 hello_world.vpj
08/05/2012 01:37 PM 206 hello_world.vpw
08/05/2012 01:37 PM 134 hello_world.vpwhist
08/05/2012 01:37 PM 106,496 hello_world.vtg
08/05/2012 07:14 AM 118 main.cpp
08/05/2012 01:38 PM 23,914 ZERO_CHECK.vcxproj
08/05/2012 01:38 PM 807 ZERO_CHECK.vcxproj.filters
15 File(s) 218,182 bytes
3 Dir(s) 134,161,678,336 bytes free
The source for my program is:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << *argv << std::endl;
return 0;
}
My CMakeLists.txt is:
# CMakeLists.txt
# $ cmake -g "NMake Makefiles" .
cmake_minimum_required(VERSION 2.8)
project(hello_world)
add_executable(hello_world main.cpp)
Thanks,