Created
June 7, 2022 21:21
-
-
Save fernandoc1/e5fb1bf4317466402ec1b5eb7ad995f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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; | |
} |
This file contains hidden or 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
extern void doTask(); | |
int main() { | |
doTask(); | |
} |
This file contains hidden or 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
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 |
This file contains hidden or 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 "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