Skip to content

Instantly share code, notes, and snippets.

@superchausette
Created August 18, 2014 20:47
Show Gist options
  • Save superchausette/0bad76dac41da43ad09b to your computer and use it in GitHub Desktop.
Save superchausette/0bad76dac41da43ad09b to your computer and use it in GitHub Desktop.
Compilation and static link of static link
#include <stdio.h>
void print_name(){
printf("LIB A\n");
}
#include <stdio.h>
void print_name(){
printf("LIB A (BIS) \n");
}
void print_name_bis() {
print_name();
}
#include <stdio.h>
#define INTERNAL __attribute__((visibility("hidden")))
INTERNAL extern void print_name();
void print_all_name() {
printf("Print all name:\n");
print_name();
}
#!/bin/bash
rm *.o 2>/dev/null
rm *.a 2>/dev/null
rm prog 2>/dev/null
echo "Compiling A"
gcc -W -g -c -o a.o a.c
ar rcs liba.a a.o
rm *.o 2>/dev/null
echo "Compiling ABIS"
gcc -W -g -c -o abis.o abis.c
ar rcs libabis.a abis.o
rm *.o 2>/dev/null
echo "Compiling B"
gcc -W -g -c -o b.o b.c
ar -x liba.a
ar rcs libb.a *.o
rm *.o 2>/dev/null
echo "Compiling PROG"
gcc prog.c -L. -lb -labis -o prog
rm *.o 2>/dev/null
#include <stdio.h>
extern void print_all_name();
extern void print_name();
extern void print_name_bis();
int main(int argc, char ** argv) {
printf("MAIN\n");
print_all_name();
print_name();
print_name_bis();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment