Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile all the c files in given directory? [closed]

Tags:

bash

terminal

I want to compile all the files in a given directory.

I don't want to use

gcc -o main file1.cpp file2.cpp file3.cpp ... 

because there are many files.

So how do I compile all the files whose extension is .cpp in a given directory using terminal/bash?

like image 261
Shrey Kumar Avatar asked Oct 28 '25 09:10

Shrey Kumar


1 Answers

You are asking for files with extension .cpp? So you can just type:

gcc -o main *.cpp

The shell expand the asterisk to file1.cpp, file2.cpp and so on of the current directory.

like image 194
dev.null Avatar answered Oct 30 '25 00:10

dev.null