Solved

Newbie Question: Using Header Files & GCC

Posted on 2004-08-31
4
194 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 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now