// Compile this as:
//
//     gcc -shared -o plugin2.so 12_dload_plugin2.c
//
// This will give you plugin2.so which can be given to 12_dload like so:
//
//     ./12_dload ./plugin2.so 10

#include <stdio.h>

// This is a "constructor" function which will be run once when the
// library is first loaded by dlsym(). This happens before dlsym()
// even returns the library pointer to the host program!
//
// These are commonly used to set up global data structures, which
// is necessary because there is no main() function in a library.
__attribute__((constructor))
void init() {
	printf("woaaaaahhhh this is running during dlopen()!\n");
}

// And this will be run when the library is unloaded, either through
// calling dlclose() (which I don't demonstrate) or when the program
// is exiting.
__attribute__((destructor))
void deinit() {
	printf("and this gets printed when the program is exiting!\n");
}

int plugin_func(int x) {
	printf("in plugin2!\n");
	return x * 7;
}