Search code examples
c++visual-studiobazel

Bazel - Unpected error near token


I'm trying to use mysys and bazel to set up my bazel environment. Following the instructions from this website, I've done fairly well until I got to the point where I have to set an environment variable to Visual Studio.

I try to use the below code to set visual studio to an environment variable

export BAZEL_VC=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC

But I then get this error:

-bash: syntax error near unexpected token `('

Reading the error, my guess is that ( tokens arent accepted. One solution would be to change the directory name. But I'd rather not do that. I was hoping if someone could offer a more C++ answer.


Solution

  • You need to quote the environment variable value in Bash:

    export BAZEL_VC="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC"
    

    I however recommend using Bazel from the Windows Command Prompt (cmd.exe), not the MSYS Bash. (Does the documentation seem to suggest running Bazel from MSYS?)

    It was true before Bazel 0.5.0 that Bazel needed to run from the MSYS shell, but it's been working well from cmd.exe for a long time.

    If you use Bazel from cmd.exe, and want to set environment variables, then you must not quote the value:

    set BAZEL_VC=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC
    

    because cmd.exe doesn't remove (nor need) the quotes like Bash does.