Create demo with compile-time linking

This commit is contained in:
Camden Dixie O'Brien 2024-12-29 11:46:04 +00:00
parent b11e79c60b
commit a8baacb742
4 changed files with 49 additions and 0 deletions

5
build.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
CFLAGS="-std=c11 -pedantic -Wall -Wextra"
mkdir -p build
clang $CFLAGS -fPIC -shared mod.c -o build/libmod.so
clang $CFLAGS -Lbuild -lmod main.c -o build/demo

22
main.c Normal file
View File

@ -0,0 +1,22 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#define _POSIX_C_SOURCE 199309L
#include "mod.h"
#include <stdio.h>
#include <time.h>
int main(void)
{
const struct timespec pause = { .tv_nsec = 16666667 };
while (1) {
printf("\33[2K\r%s", getmsg());
fflush(stdout);
nanosleep(&pause, NULL);
}
return 0;
}

11
mod.c Normal file
View File

@ -0,0 +1,11 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include "mod.h"
const char *getmsg(void)
{
return "hi";
}

11
mod.h Normal file
View File

@ -0,0 +1,11 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#ifndef MOD_H
#define MOD_H
const char *getmsg(void);
#endif