?
Solved

Newbie Question: Using Header Files & GCC

Posted on 2004-08-31
4
Medium Priority
?
201 Views
Last Modified: 2010-04-15
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.



------------test1.c---------
int sum(int a, int b)
{
        return a + b;
}


-----------test1.h----------
int sum(int a, int b);


-----------test2.c---------
#include "test1.h"

int main()
{
        printf("%d\n", sum(4,5));
}
0
Comment
Question by:bobwood2000
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 11945606
You should use

gcc -o test test1.c test2.c

That's it.
0
 
LVL 86

Expert Comment

by:jkr
ID: 11945624
BTW, tested that with gcc version 2.96
0
 
LVL 86

Expert Comment

by:jkr
ID: 11945704
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.
0
 

Author Comment

by:bobwood2000
ID: 11946126
Thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question