Skip to content

Instantly share code, notes, and snippets.

@Cylix
Created October 19, 2020 05:06
Show Gist options
  • Save Cylix/793a5c2308acb5660292c39ba8accd15 to your computer and use it in GitHub Desktop.
Save Cylix/793a5c2308acb5660292c39ba8accd15 to your computer and use it in GitHub Desktop.
Reflection in C++14 - dlopen & dlsym
#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