Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling vcvars from bash script

I need to call vcvars32.bat and vcvars64.bat from within the same bash script (msys) which builds different version of my application.

The problem is that, even if I am able to call the batch files with the cmd.exe command, once it returns the Visual Studio variables are obviously not set.

I cannot call vcvars from an external batch file (like msys.bat) which call the bash script, as I need in the same script to call both of them sequentially.

So, is there any way to call vcvars in order to properly set the variables in the bash script while running?

like image 379
martjno Avatar asked Mar 02 '13 08:03

martjno


1 Answers

One way to solve this is to run your commands from within the vcvars environment, rather than trying to export it back to the bash side. That's the approach we've chosen for our project.

The main problem is that vcvars*.bat doesn't accept commands to execute in the environment, so a little bit of trickery with cmd is required. So I came up with a simple Bash script called vcvars_env_run.sh that accepts arbitrary arguments and forwards them to a cmd.exe on which vcvars64.bat has been called. The bulk of the work is figuring out how to properly forward quoted arguments, and things like &&, ||, return codes, etc.

I've uploaded the script and some examples at https://github.com/kromain/wsl-utils

You might need to tweak it a little to switch between vcvars32.bat and vcvars64.bat, but hopefully it helps for what you're trying to do.

like image 141
Romain Pokrzywka Avatar answered Nov 01 '22 21:11

Romain Pokrzywka