Solved

Newbie Question: Using Header Files & GCC

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

Technology Partners: 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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

738 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