Skip to content

Instantly share code, notes, and snippets.

@sky87
Last active February 7, 2023 02:42
Show Gist options
  • Save sky87/a887cef73285ab88b303f03295d0821e to your computer and use it in GitHub Desktop.
Save sky87/a887cef73285ab88b303f03295d0821e to your computer and use it in GitHub Desktop.
# Add to ~/.bashrc
# call load_msenv from a shell to load the enviroment
function load_msenv() {
local msenv="$HOME/.msenv_bash"
if [ ! -f "$msenv" ]; then
local msenvbatch="__print_ms_env.bat"
echo "@echo off" > "$msenvbatch"
echo "call ${VS140COMNTOOLS}..\..\VC\vcvarsall.bat x64" >> "$msenvbatch"
echo "set" >> "$msenvbatch"
cmd "/C $msenvbatch" > "$msenv.tmp"
rm -f "$msenvbatch"
grep -E '^PATH=' "$msenv.tmp" | \
sed \
-e 's/\(.*\)=\(.*\)/export \1="\2"/g' \
-e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \
-e 's/\\/\//g' \
-e 's/;\//:\//g' \
> "$msenv"
# Don't mess with CL compilation env
grep -E '^(INCLUDE|LIB|LIBPATH)=' "$msenv.tmp" | \
sed \
-e 's/\(.*\)=\(.*\)/export \1="\2"/g' \
>> "$msenv"
rm "$msenv.tmp"
fi
source "$msenv"
}
export -f load_msenv
@andlabs
Copy link

andlabs commented Sep 4, 2019

Thanks! Note that you may need to add extra quotes around ${VS140COMNTOOLS}..\..\VC\vcvarsall.bat depending on... I'm not sure what exactly, but I know I did.

@kalj
Copy link

kalj commented Apr 7, 2021

Thanks. I made a fork with some improvements:

  • Tried to make paths generic
  • Works with both VS 2017 and VS 2019

@electrocnic
Copy link

Did not work for me :(
Not even with sudo load_msenv.
I expect afterwards that ninja --version would be working, but it still says bash: ninja: command not found.

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