• C

Newbie Question: Using Header Files & GCC

Below are the 3 files (2 .c files, 1 .h file) in the program I want to compile using GCC. What commands and flags do I need to use in order to compile this program, so that I can run test2.c?  Thanks.

int sum(int a, int b)
        return a + b;

int sum(int a, int b);

#include "test1.h"

int main()
        printf("%d\n", sum(4,5));
Who is Participating?
jkrConnect With a Mentor Commented:
You should use

gcc -o test test1.c test2.c

That's it.
BTW, tested that with gcc version 2.96
More info - the executable that the above command produces is called 'test' (actually, you can choose any arbitrary name with the '-o' argument) and it is not necessary to specify any header files on the command line.
bobwood2000Author Commented:
Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.