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
gcc -Wall -Wextra -Werror -pedantic -o program ./main.c ./file.cwill build what you want in a single command. Beyond that, consider using a makefile or cmake (strongly advise the latter, btw).program.exeon the mac, and the mac doesn't use backslashes as path separators. So the correct command is./programnot./program.exe