Mix different C source files into a single one

H

Horacius ReX

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
 
M

Michael L Torrie

Horacius said:
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).
 
J

John Machin

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
 
B

Benjamin

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. :))
 
G

Grant Edwards

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top