Created
October 19, 2020 05:06
-
-
Save Cylix/793a5c2308acb5660292c39ba8accd15 to your computer and use it in GitHub Desktop.
Reflection in C++14 - dlopen & dlsym
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 <dlfcn.h> | |
#include <iostream> | |
extern "C" { | |
void display_nb(int nb) { | |
std::cout << nb << std::endl; | |
} | |
} | |
int main(void) { | |
auto handler = dlopen(nullptr, RTLD_LAZY); | |
auto fct = reinterpret_cast<void(*)(int)>(dlsym(handler, "display_nb")); | |
fct(42); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment