Sublime Forum

Custom build : g++.sublime-build

#1

Hello,

I’m trying to make my own sublime-build that’ll run “g++ -W -Wall -Werror *.cpp” in the directory of the current directory.
For the moment, I’ve this :

{
	"cmd": "/usr/bin/g++", "-W", "-Wall", "-Werror", "$file"],
	"working_dir": "${file_path}"
}

But it runs only on the current file (g++ -W -Wall -Werror main.cpp)

I’ve already tried :

{
	"cmd": "/usr/bin/g++", "-W", "-Wall", "-Werror", "*.cpp"],
	"working_dir": "${file_path}"
}

But it tries on a file “*.cpp” not on the pattern *.cpp

i686-apple-darwin11-llvm-g++-4.2: *.cpp: No such file or directory
i686-apple-darwin11-llvm-g++-4.2: no input files
0 Likes

#2

Bump

0 Likes

#3

“*.cpp” will pass *.cpp as a literal argument to g++. Usually the shell would expand glob patterns before launching the process, if you want to use shell features, then try this instead:

{
   "cmd": "/usr/bin/g++ -W -Wall -Werror *.cpp"],
   "working_dir": "${file_path}",
   "shell": true
}

Alternatively, you can explicitly call bash in the “cmd”, or call a shell script.

0 Likes

#4

Thanks, works great :smile:

0 Likes

#5

I’ve made it possible to build and run with this:
{
“cmd”: “gcc -Wall ${file} -o ${file_base_name} && ./${file_base_name}”],
“working_dir”: “${file_path}”,
“shell”: true
}

Thanks a lot!

0 Likes