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

cannot use PATH/LD_LIBRARY_PATH for Windows binaries #2167

Closed
darealshinji opened this issue May 28, 2017 · 5 comments
Closed

cannot use PATH/LD_LIBRARY_PATH for Windows binaries #2167

darealshinji opened this issue May 28, 2017 · 5 comments

Comments

@darealshinji
Copy link

Microsoft Windows: Version 10.0.15063

On command prompt I can set PATH to make binaries search for DLLs in other directories. But doing the same in bash doesn't work. Setting LD_LIBRARY_PATH doesn't work either. It can't find the required DLLs unless I change the working directory.

Here's an example:

C:\>cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64_x86

C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64_x86>cl.exe

C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64_x86>set PATH=C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64;%PATH%

C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64_x86>cl.exe
Microsoft (R) C/C++-Optimierungscompiler Version 19.00.24218.2 für x86
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Syntax: cl [ Option... ] Dateiname... [ /link Linkeroption... ]

The same in bash:

djcj@DESKTOP-J6KIB79:~$ cd "/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86"
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$ ./cl.exe
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$ export PATH="/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64:$PATH"
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$ ./cl.exe
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$ export LD_LIBRARY_PATH="/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64"
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$ ./cl.exe
djcj@DESKTOP-J6KIB79:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64_x86$

In this example I was expecting ./cl.exe to find the DLLs from the other directory and to run properly.

@sunjoong
Copy link

sunjoong commented May 28, 2017

@darealshinji - Try like this if cl.exe is in "C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin\amd64";

djcj@DESKTOP-J6KIB79:~$ export PATH='/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/14.0/VC/bin/amd64':$PATH
djcj@DESKTOP-J6KIB79:~$ cl.exe

UPDATE: After more deep search, I think, it looks like not just a simple PATH problem; https://stackoverflow.com/questions/366928/invoking-cl-exe-msvc-compiler-in-cygwin-shell . You might need to rewrite contents of vcvars32.bat to shell script.

@darealshinji
Copy link
Author

darealshinji commented Jun 8, 2017

Let me give you a better example: I have yasm.exe which requires yasm.dll and yasmstd.dll.
Let's assume I put the DLLs into the sub-directory dlls:
in command prompt I can add this directory to PATH with set PATH=%CD%\dlls;%PATH% and then yasm.exe will work.
However, when I try the same in Bash with export PATH="$PWD/dlls:$PATH" or export LD_LIBRARY_PATH="$PWD/dlls" it won't work.

edit:

Appearently I can use cmd.exe in Bash to set the PATH and then run the command:
cmd.exe /C 'set PATH=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/Hostx64/x64;%PATH% & "C:/Program Files (x86)/M icrosoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/Hostx64/x86/cl.exe"'

However I wish there was an easier solution.

@sunjoong
Copy link

sunjoong commented Jun 8, 2017

However, when I try the same in Bash with export PATH="$PWD/dlls:$PATH" or export LD_LIBRARY_PATH="$PWD/dlls" it won't work.

@darealshinji - Yes, I could not find the way how to set windows PATH environment variable within WSL too. In this condition, the most simplest way is to set windows PATH environment variable on windows using control pannel-user account-user account-environment variable before launching WSL.

I coppied C:\msys64\usr\bin\bsdtar.exe to C:\Users\sunjoong\Desktop directory, and bsdtar.exe need msys-2.0.dll (and more dlls) but there were no such dlls in that directory.
ldd
I could run C:\Users\sunjoong\Desktop\bsdtar.exe becasue I had appended C:\msys64\usr\bin to windows Path environment variable.

EDIT: You know, bsdtar.exe is a Msys2 binary, in other words, it's a windows binary that needs msys2-2.0.dll. I tested weither it could be run on WSL in the directory that does not have that dll.

UPDATE: I hit upon why @darealshinji raised this issue could be related to #1494 and/or #1363.

@davidhunter22
Copy link

The cmd.exe /C 'set PATH...' worked great for me. In my ideal world though be able to use PATH and LD_LIBRARY_PATH in a bash shell for a Windows binary in the same way as I would for a Linux binary. Note that the title of this article is about PATH but LD_LIBRARY_PATH is as important. If getting PATH and LD_LIBRARY_PATH to work right is hard for Windows binaries would something like a WINDOWS_PATH in bash to mean "append this to the Windows PATH before executing a Windows binary" be easier?

@darealshinji darealshinji changed the title cannot use $PATH as dll search path for Windows binaries cannot use PATH/LD_LIBRARY_PATH for Windows binaries Aug 25, 2017
@therealkenc
Copy link
Collaborator

In this example I was expecting ./cl.exe to find the DLLs from the other directory and to run properly.

It is possible to get cl.exe (or anything else) to run via interop, but you'll need everything typically set up by vcvars.bat set up. Linux LD_LIBRARY_PATH is unrelated. The Linux loader doesn't know how to load those dlls, and cl.exe isn't running in the WSL environment.

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

No branches or pull requests

4 participants