471,350 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

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 type of python script able to do this kind of
task ?

Thanks
Dec 29 '07 #1
4 1118
Horacius ReX wrote:
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 type of python script able to do this kind of
task ?
No, but bash and friends can:

cat *.c newfile.c

If you're stuck working with windows, the copy command can also
concatenate files.

After concatenating the files, editing the file to remove/merge #include
directives would work. Any compiler that can only deal with a single
source file is of course extremely limited in what it can do, so this
manual process shouldn't be too bad for short programs (all that this
compiler can really deal with).
>
Thanks
Dec 29 '07 #2
On Dec 30, 5:05 am, Horacius ReX <horacius....@gmail.comwrote:
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.
The relevance of this question to this newsgroup is zero, but ...

Smashing all of your source files into one is an "interesting"
reaction to the perceived problem. Consider these alternatives:

1. Abandon any further trialling of this new compiler ... which new
compiler is it? Which compiler are you currently using?

2. Use "make" or something similar to automate the process of
compiling each changed source file followed by a linking step.

3. Write yourself a shell script that compiles each source file and
then links it.

HTH,
John
Dec 29 '07 #3
On Dec 29, 12:05 pm, Horacius ReX <horacius....@gmail.comwrote:
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.
That sounds like one crumy compiler.
>
Do you know about some type of python script able to do this kind of
task ?
No, but we can write one:

import sys

if __name__ == "__main__":
glob = ""
for file in sys.argv[1:-1]:
glob += "\n" + open(file, "r").read()
open(sys.argv[-1], "w").write(glob)

It's stupid, but it'll work for basic tasks. (I would actually just
use cat; that's what it's for. :))
>
Thanks
Dec 29 '07 #4
On 2007-12-29, Horacius ReX <ho**********@gmail.comwrote:
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.
That's pretty much the way they all work.
So I need to "mix" all my different C source files into a
single one.
You compile them individually, then you link the object files
together.
Do you know about some type of python script able to do this
kind of task ?
$ man make

--
Grant

Dec 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by A_StClaire_ | last post: by
11 posts views Thread by Roy | last post: by
5 posts views Thread by Horacius ReX | last post: by
reply views Thread by Sells, Fred | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.