[LINUX] Build fails with `/bin/sh: 1: Syntax error: "(" unexpected` when using shadow build outside project directory parent containing bracket "("
-
This is a very edge case but it is also about the more general question of how to customize the shell used to build a Qt project on Linux.
Repro
- Create a directory containing a bracket "(" or ")" in the name, such as "test (bracket)"
- Create a new Qt project inside this directory
- Go to Project Build Settings, check Shadow Build
At this point, build works correctly, because everything happens inside "test (bracket)" so the g++ command can use the relative path
../TestBracket/main.cpp
.
- Still in Project Build Settings, under Shadow Build, change the Build directory to move one level up, by removing "test (bracket)"
- Build project
Result: Build fails with
/bin/sh: 1: Syntax error: "(" unexpected
/ ")" unexpected`This time, the g++ command needs to refer to
../test\ (bracket)/TestBracket/main.cpp
Note that Qt projects cannot contain space/bracket in the name at creation time, but may after copying/renaming them. Actually I found this bug precisely after duplicating a project and adding brackets in the name (in which case the error happens even if the Shadow Build path is not moved one level above, as the project name itself would contain a bracket).
Similar issues
I only found https://forum.qt.io/topic/67061/error-from-bin-sh-when-compiling-under-linux to be similar, although it was failing due to a Windows path "Program Files (x86)", hence the brackets. This makes me think, by the way, that the order only happens on Linux, maybe OSX.
Possible solution
According to https://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected, using
env bash
would allow the g++ command to recognize brackets in side double quotes, unlikesh
. I don't see how to customize the shell in Qt on Linux, however.Workaround
When using Shadow Build, do not put round brackets "(" nor ")" in any directory of your path to project; or at least, in any directory under where you'll put your Shadow Build.
In my case, the path to project was rendering absolute for some reason, so I really needed it clean.Interestingly, I was checking if my .pro files were supporting spaces, but those were escaped correctly when using $$ without the need for extra double quotes. The g++ command, however, is very generic and doesn't really care about the content of .pro.
-
Hi @huulong,
very nicely summed up!
I've already created QTCREATORBUG-20834 some time ago, and your case fits perfectly there.
You may comment and vote on that bug, so we at least get a warning from the IDE.
Regards