How can I compile my C source files without needing to put a main
function within them?
I get an error for the .c
files that have no main fu
You can compile individual files without main
, but you cannot link them and of course cannot run them since they are not complete programs. Note that valgrind is not a static analysis tool but a runtime tool, and therefore it is useless on individual translation units not linked into a runnable program.
If you want to test individual files, a common practice is to include something like the following in each file:
#ifdef UNIT_TEST
int main(int argc, char **argv)
{
/* unit test code goes here */
}
#endif
And compile the file with -DUNIT_TEST
.