I have a bunch of directories with C programs. I need to compile them one by one and use the result in the main Program.
So my Main program traverse in the Directory structure [I am not sure what the structure is, It may change over time] and compiles one C program at a time, use that result in some computation.
So If I write the main program in C and use nftw to traverse.
OR
Write a Shell main program.
Which appraoch is better?
I guess you use a compatible Unix/Linux/Cygwin system….
Therefore, I would advice to use a shell solution because it is more suitable for directory processing.
Makefilefor each programAs @Dogbert said
makecan be used to build several programs. Build can be performed in parallel (using the option-j). Moreovermakecan also take care about the dependencies.I do not know if you are used with
Makefilesyntax. Therefore I give a quick example about a program requiring threeCfiles and one header file:The following command will compile
file1.c,file2.candfile3.cin parallel. Then link stage will wait for the completion of these tree compilations.Directory discovery
The following command finds each
Makefileand runs themakecommand:If you have 8 cores in your computer, you can use
-j8.Reuse in your main program
The build result is displayed on the shell screen and is also stored in the
result.txtfile.More information?
I do not know what is your system, or your knowledge. Hope this can help. If you are not sure to understand some parts, please ask for more information. 😉