Solved

Newbie Question: Using Header Files & GCC

Posted on 2004-08-31
4
191 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
Comment Utility
You should use

gcc -o test test1.c test2.c

That's it.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
BTW, tested that with gcc version 2.96
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
Thank you!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

762 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

11 Experts available now in Live!

Get 1:1 Help Now