如何编译所有.cpp文件,除了使用g ++的文件?

问题描述 投票:0回答:3

要编译我的源目录中的所有C ++文件,我运行

g++ -std=c++17 ../src/*.cpp -o ../out/a.out

除了cpp之外,如何编译给定目录中的所有main.cpp文件?

bash g++
3个回答
2
投票

庆典:

shopt -s extglob
g++ -std=c++17 ../src/!(main).cpp -o ../out/a.out

ref:https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching


1
投票
for f in $(find /path/to/files -name "*.cpp" ! -name "main.cpp")
do
  g++ -std=c++17 path/to/files/"$f" -o /path/to/out/....
done

1
投票

我们可以将glob过滤成Bash数组:

unset files
for i in ../src/*.cpp
do test "$i" = '../src/main.cpp' || files+=("$i")
done

g++ -std=c++17 "${files[@]}" -o ../out/a.out

或者,using GNU grep and mapfile

mapfile -d $'\0' -t files < <(printf '%s\0' ../src/*.cpp | grep -zv '/main\.cpp$')
g++ -std=c++17 "${files[@]}" -o ../out/a.out
© www.soinside.com 2019 - 2024. All rights reserved.