Tomorrow I have a test for a company. My files must be easy to compile with Coliru (web compiler) : http://coliru.stacked-crooked.com/
But here is my problem : "How do I use multiples files in Coliru ?" I read the Q&A but didn't succeed to do it.
Here is the program I wanted to test :
#include <stdlib.h>
#include <stdio.h>
//MyLibraries
#include "Addition.c"
int main(int argc, char * argv[])
{
Addition();
return EXIT_SUCCESS;
}
And this is my "Addition.c" file :
#include <stdio.h>
#include <stdlib.h>
void Addition(int a, int b);
void Addition(int a, int b)
{
printf("%d", (a + b));
}
If somebody can explain to me how to compile multiple files with Coliru, it'll be awesome. Thx
There's this comment in the Coliru issue tracker that suggests the following way.
==> Makefile <==
main.cpp
by Coliru) into the source field, use the following build command (I'm copying it here with the comment from the link, for attribution):# Here is a cool technique to use Coliru for small "Makefile projects":
# (No need to say "thanks" but if you feel inclined: coliru [at] tbfe.de)
pr -ti main.cpp|awk '/==> [^ ]+ <==/ {f=$2;next} {print>>f}' && make
How this script works:
pr -ti
converts 8-chars into tabs (for the Makefile
to be syntactically valid) awk ...
finds the header line, extracts the filename from it and then writes everything until the next header into corresponding file make
simply works on the resulting set of files. How to convert your project to this format:
for file in *; do printf "==> $file <==\n" >> main.cpp; cat "$file" >> main.cpp; done
Note : make sure that your project doesn't have a file named main.cpp
, or you'll need to adjust the build script (and the generator script).
The live example is taken from the same link above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.