Skip to content

Instantly share code, notes, and snippets.

@27thLiz
Created February 16, 2017 22:07
Show Gist options
  • Save 27thLiz/7674a962bd3ed1430dca94ad33bd6e0c to your computer and use it in GitHub Desktop.
Save 27thLiz/7674a962bd3ed1430dca94ad33bd6e0c to your computer and use it in GitHub Desktop.
Try to replicate app launcher behavior
#include "app.h"
#include <stdio.h>
int get_version() {
return 2;
}
void run() {
printf("version h: %d\n", VERSION);
printf("version lib: %d\n", get_version());
}
#ifndef APP_H
#define APP_H
#define VERSION 2
int get_version();
void run();
#endif
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "libtest.h"
int main(int argc, char *argv[])
{
void (*run)();
void *app = dlopen("./app.so", RTLD_LAZY);
if (!app) {
exit(EXIT_FAILURE);
}
*(void **) (&run) = dlsym(app, "run");
if (dlerror() != NULL) {
exit(EXIT_FAILURE);
}
(*run)();
printf("version launcher: %d\n", get_version());
dlclose(app);
return EXIT_SUCCESS;
}
#include "libtest.h"
int get_version() {
return 1;
}
#ifndef LIBTEST_H
#define LIBTEST_H
#define VERSION 1
int get_version();
#endif // LIBTEST_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment