473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1195
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
7
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
11
by: Roy | last post by:
Hi , could you please list the reasons why we different C files for writing code . We use header files to logically group functionality that is related . Is there any other reason why we need...
2
by: dolphin | last post by:
What is the different between c++ call convention and c call convention?Can some give some examples?
0
by: tomPee | last post by:
Hi, I have no idea if this is the right section to post this in. But i thought it maybe belonged here most. The problem i having is actually, most likely really simple. But here i am running...
5
by: Horacius ReX | last post by:
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...
0
by: Sells, Fred | last post by:
the short answer is a file is a module; therefore to 'include' access to 'myclass' in file xyz.py from another file called 'abc.py' you would put this in abc.py import xyz #note no '.py' x =...
7
by: JoeC | last post by:
I am trying to create a windows program that reads binary graphics as a resource. This has nothing to do with win32 but conversion of data with memcpy. graphic::graphic(UINT uiResID, HINSTANCE...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.