Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Created June 7, 2022 21:21
Show Gist options
  • Save fernandoc1/e5fb1bf4317466402ec1b5eb7ad995f6 to your computer and use it in GitHub Desktop.
Save fernandoc1/e5fb1bf4317466402ec1b5eb7ad995f6 to your computer and use it in GitHub Desktop.
#include "a.h"
A::A() {
std::cout << "New A" << std::endl;
}
A::~A() {
std::cout << "Destroying A" << std::endl;
}
void A::print() {
std::cout << "Printing A" << std::endl;
}
extern void doTask();
int main() {
doTask();
}
all:
g++ -fPIC -shared test.cpp -o libtest.so -ldl
g++ a.cpp -shared -fPIC -o liba.so
g++ -Wl,--unresolved-symbols=ignore-in-shared-libs main.cpp libtest.so
#include "a.h"
#include <dlfcn.h>
void doTask() {
void* handle = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL);
A* a = new A();
a->print();
delete a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment