Created
February 16, 2017 22:07
-
-
Save 27thLiz/7674a962bd3ed1430dca94ad33bd6e0c to your computer and use it in GitHub Desktop.
Try to replicate app launcher behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef APP_H | |
#define APP_H | |
#define VERSION 2 | |
int get_version(); | |
void run(); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "libtest.h" | |
int get_version() { | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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