I am creating a File Management System in my Operating Systems Project. I have different C files for copying a file, deleting a file, changing extension, displaying content and many more. Now, I want to run all of these files as one file/program. Is it possible other than combining all codes into one file?
Asked
Active
Viewed 7,041 times
2
-
Rename the `main` of each and write an overarching `main`. – Paul Ogilvie Nov 02 '17 at 10:35
-
...and look at `make` to compile all the source modules and link them into a single executable – Paul Ogilvie Nov 02 '17 at 10:36
-
Possible duplicate of [Compile multiple C files with make](https://stackoverflow.com/questions/2604398/compile-multiple-c-files-with-make) – Joe Nov 02 '17 at 11:01
-
Any half-decent C build system supports a linker. I suppose that is the hazard of creating your own OS, having to invent everything from scratch. Make it so. – Hans Passant Nov 02 '17 at 11:11
-
2How is it possible that you have an operating systems project yet do not know anything about the **linking of multiple translation units**?! – Antti Haapala -- Слава Україні Nov 02 '17 at 11:14
-
@AnttiHaapala it's likely a school project. Most school's these don't don't really focus much on C unfortunately, so it could be only OP's second or third time using C, and it's possible he's never had to compile more than one file. – CoffeeTableEspresso Jun 06 '19 at 22:03
1 Answers
4
main()
should exist in only one file.
Then you just compile and link them all together:
gcc copy.c delete.c extension.c list.c your_app.c -o you_app
This is usually managed using Make.

Joe
- 7,378
- 4
- 37
- 54