Conner
Conner

Reputation: 11

Compile Multiple C Files on Mac?

I am new to C and using GCC. How do I compile multiple C files and then run them? I have multiple miles and each has different functions and they are supposed to run through the main.c file. My friend showed me through Windows but I am having issues figuring out how to do it on Mac.

What I was told: Compile both files individually first:

gcc -Wall -c .\main.c
gcc -Wall -c .\file.c

Then compile both together into an executable:

gcc -o program file.o main.o

Then run executable with .\program.exe

Upvotes: 0

Views: 932

Answers (1)

Chris
Chris

Reputation: 36596

You should probably investigate makefiles, but this is quite easy. The following should do the trick.

gcc -o program file.c main.c

Feel free to add in whichever -W warning flags you want.

Note also that Macs do not use \ as a directory separator but rather /, and executable files do not typically end in .exe.

Upvotes: 2

Related Questions