LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 12-29-2007, 12:01 PM   #1
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Rep: Reputation: 15
Mix different C source files into a single one


Hi,

I have a C program split into different source files. I am trying a new compiler and for some reason it only accepts a single source file. So I need to "mix" all my different C source files into a single one.

Do you know about some program able to do this kind of task ?

Thanks
 
Old 12-29-2007, 12:06 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
No..

What compiler are you using? I've never heard of a compiler that can't handle multiple sources files....
 
Old 12-29-2007, 12:09 PM   #3
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Original Poster
Rep: Reputation: 15
it is some kind of a special compiler developed by some company for some specific architecture (kind of arm)

the thing is that I can not avoid this !


Quote:
Originally Posted by jtshaw View Post
No..

What compiler are you using? I've never heard of a compiler that can't handle multiple sources files....
 
Old 12-29-2007, 01:02 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

How about this:

Code:
cat *.h *.c >> bigfile.c
You know that if this C compiler is so idiosyncratic that it doesn't even support multiple source files, you're going to have your work cut out trying to port code to it. Merging source is probably going to be the least of your problems.

Good luck .. PSM

PS:
If the original source doesn't already do it, you'll need to do two extra things manually:
Quote:
a) Put "guards" around each include file:
Code:
#ifndef _MY_INCLUDE_H
#define _MY_INCLUDE_H
  ... the rest of the header ...
#endif
b) Create prototypes for each function (before the function is first used!)
<= This lets you use any function in any order: you don't have to worry about "duplicate definitions"

Last edited by paulsm4; 12-29-2007 at 11:37 PM.
 
Old 12-30-2007, 12:54 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Depending on the code complexity you may not be able to just do a cat operation. The headers need to be added in the order declarations are used. For example, if header X.h requires type struct zzz in header Y.h then you'll need to place the Y.h code before X.h. Assuming the compiler can handle includes, though, you could just cat the sources into a single file and leave the headers alone.
ta0kira
 
Old 12-30-2007, 12:16 PM   #6
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
If the compiler does support #include, then you can create an "everything.c" that includes all of the other .c files (it's fairly easy to generate it with the various build tools). If it doesn't support #include (that would be insane), then you can get GCC to expand all of that with -E.
 
Old 01-08-2008, 10:24 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Depending on how the sources were written, you also might need to watch out for duplicate static symbols in the sources. That's really the only problem I see with consolidating source files.
ta0kira
 
  


Reply



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
Building a single .ko file from multiple source files rajesh_b Programming 2 04-01-2007 12:51 PM
Oignon routing: Mix and mix cascades xpucto Linux - Networking 6 07-05-2006 12:01 PM
LXer: Mix-and-match open source for corporate networks LXer Syndicated Linux News 0 05-03-2006 01:24 AM
LXer: Open Source and Anti-Virus Don't Mix LXer Syndicated Linux News 0 04-18-2006 12:54 AM
Any applications/converters for *.mix files slackist Linux - General 3 04-19-2004 09:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration