ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ?
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"
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.