?
Solved

Newbie Question: Using Header Files & GCC

Posted on 2004-08-31
4
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

752 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