This is a demonstration of multiple source code compilation in the book "Linux Programming Unleashed 2nd Edition" from SAMS publishing page 48:
There are three seperate files in the same directory,
helper.c
Code:
/*
* helper.c - Helper code for howdy.c
*/
#include <stdio.h>
void msg(void)
{
printf("This message sent from Jupiter.\n");
}
helper.h
Code:
/*
* helper.h - Header for helper.c
*/
void msg(void)
howdy.c
Code:
/*
* * howdy.c - Canonical "Hello, world!" program
* */
#include <stdio.h>
#include "helper.h"
int main(void)
{
printf("Hello, Linux programming world!\n");
return 0;
}
This is compiled, according to the book,
Code:
gcc howdy.c helper.c -o howdy
But, I get the following errors:
Code:
howdy.c: In function `msg':
howdy.c:8: parse error before `{'
howdy.c:8: declaration for parameter `main' but no such parameter
howdy.c:10: number of arguments doesn't match prototype
cc1: prototype declaration
I have been through numerous C++ texts and this is the first time I have seen anything like an elementary example and explanation of how to use the preprocessor directives. And even here there is very little encouragement. For example, what is the difference between a library enclosed in '<>' and one enclosed in '""'? What is the purpose of the code in the helper.h?