LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-31-2005, 07:52 AM   #1
introuble
Member
 
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 ?

i.e:

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, 08:50 AM   #2
sind
Member
 
Registered: Jun 2005
Posts: 75

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

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

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

Rep: Reputation: 46
Quote:
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

Code:
/* declaration */
int factorial(int);

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


Reply


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 06:58 AM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM
Using g++ to compile multiple source files arnab_be Linux - Newbie 1 03-03-2004 02:22 PM
Using g++ to compile multiple source files arnab_be Linux - Newbie 1 03-03-2004 02:21 PM
I need help using multiple source files CodeWarrior Programming 4 12-30-2003 04:18 AM


All times are GMT -5. The time now is 05:19 PM.

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