|
| 1 | +# Examples of Compiling and Running |
| 2 | + |
| 3 | +## Hello, World! |
| 4 | +To begin, a simple "Hello World" file can be created. In this case, as follows: |
| 5 | +```c |
| 6 | +#include <stdio.h> |
| 7 | + |
| 8 | +int main() { |
| 9 | + printf("Hello, World!\n"); |
| 10 | + return 0; |
| 11 | +} |
| 12 | + |
| 13 | +``` |
| 14 | +First, it can be compiled and run as usual with native gcc: |
| 15 | +```bash |
| 16 | +gcc hello.c -o hello |
| 17 | +./hello |
| 18 | +``` |
| 19 | + |
| 20 | +Then under lind, where it should produce the same output: |
| 21 | +``` |
| 22 | +./lindtool.sh cptest hello |
| 23 | +./lindtool.sh run hello |
| 24 | +``` |
| 25 | +<!-- A sample output is shown below: |
| 26 | +<a href="../../images/hello_screenshot1.png" target="_blank"> |
| 27 | +  |
| 28 | +</a> --> |
| 29 | + |
| 30 | +## Example with Header file included |
| 31 | + |
| 32 | +Header files can be included in the same way. Below is a simplified example: |
| 33 | +#### `print_it.h`: |
| 34 | +``` |
| 35 | +#ifndef PRINT_IT_H |
| 36 | +#define PRINT_IT_H |
| 37 | +
|
| 38 | +#include <stdio.h> |
| 39 | +#include <time.h> |
| 40 | +
|
| 41 | +static inline void print_it(const char *message) { |
| 42 | + time_t now = time(NULL); |
| 43 | + struct tm *t = localtime(&now);char timestamp[20]; |
| 44 | + strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", t); |
| 45 | + printf("%s %s\n", timestamp, message); |
| 46 | +} |
| 47 | +
|
| 48 | +#endif |
| 49 | +``` |
| 50 | +#### `helloworld.c`: |
| 51 | +```c |
| 52 | +#include "print_it.h" |
| 53 | + |
| 54 | +int main() { |
| 55 | + print_it("Hello, World!"); |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +``` |
| 60 | +Again, it can be compiled and run as usual with native gcc: |
| 61 | +```bash |
| 62 | +gcc helloworld.c -o helloworld |
| 63 | +./helloworld |
| 64 | +``` |
| 65 | + |
| 66 | +Then under lind, where it should produce the same output: |
| 67 | +``` |
| 68 | +./lindtool.sh cptest helloworld |
| 69 | +./lindtool.sh run helloworld |
| 70 | +``` |
| 71 | +<!-- A sample output is shown below: |
| 72 | +<a href="../../images/hello_screenshot2.png" target="_blank"> |
| 73 | +  |
| 74 | +</a> --> |
0 commit comments