Skip to content

Instantly share code, notes, and snippets.

@jmroot
Created September 5, 2022 06:08
Show Gist options
  • Save jmroot/4bf947e3d0280f7d5b3ec934bdcb68e5 to your computer and use it in GitHub Desktop.
Save jmroot/4bf947e3d0280f7d5b3ec934bdcb68e5 to your computer and use it in GitHub Desktop.
Script to test compatibility_version behaviour
#!/bin/sh
CC=${CC-clang}
echo '#include <stdio.h>
#include "lib.h"
int libcall(void) {
printf("working\\n");
return 0;
}
' > ./lib.c
echo 'int libcall(void);
' > ./lib.h
echo '#include "lib.h"
int main(void)
{
libcall();
return 0;
}
' > main.c
$CC -c lib.c -o lib.o
$CC -dynamiclib -current_version 1.0.0 -compatibility_version 1.0.0 \
-install_name '@executable_path/lib.1.dylib' lib.o -o lib.1.0.0.dylib
$CC -dynamiclib -current_version 2.0.0 -compatibility_version 2.0.0 \
-install_name '@executable_path/lib.1.dylib' lib.o -o lib.2.0.0.dylib
ln -sf ./lib.1.0.0.dylib ./lib.1.dylib
$CC main.c ./lib.1.dylib -o testprog
echo "Built against lib 1.0.0; running with lib 1.0.0"
./testprog
echo "Built against lib 1.0.0; running with lib 2.0.0"
ln -sf ./lib.2.0.0.dylib ./lib.1.dylib
./testprog
$CC main.c ./lib.1.dylib -o testprog
echo "Built against lib 2.0.0; running with lib 2.0.0"
./testprog
ln -sf ./lib.1.0.0.dylib ./lib.1.dylib
echo "Built against lib 2.0.0; running with lib 1.0.0"
./testprog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment