Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-31-2005, 08:52 AM   #1
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
multiple C source files howto

Ok ..

So how would you do this under linux:

You have a program and you want cirtain "functions" to be in sepparate source files .. how would you compile this program ?


main.c : contains "main" function which calls function 'test", includes "prog.h"

prog.h : definition for function "test"

test.c : body of function test

Old 07-31-2005, 09:50 AM   #2
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
It can be as simple as:

$ gcc -o program main.c test.c
Or, you can have seperate commands for each step:

$ gcc -c main.c
$ gcc -c test.c
$ gcc -o program main.o test.o
Old 07-31-2005, 08:49 PM   #3
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
prog.h: definition of "test"
test.c: body of "test"
The definition of a function *is* it's body.

I think you mean that the *declaration* is in prog.h

/* declaration */
int factorial(int);

/* definition */
int factorial(int n) {
  if (!n) return 1;
  return n * factoral(n - 1);
hth --Jonas


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
howto network syslog with multiple log files mcalizo Red Hat 2 05-27-2005 07:58 AM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 06:25 PM
Using g++ to compile multiple source files arnab_be Linux - Newbie 1 03-03-2004 03:22 PM
Using g++ to compile multiple source files arnab_be Linux - Newbie 1 03-03-2004 03:21 PM
I need help using multiple source files CodeWarrior Programming 4 12-30-2003 05:18 AM

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration