Referencing global symbols from shared library loaded with dlopen
问题 I have a shared library which I want to access symbols from the main program. For example: main.c #include <stdio.h> void bar(void) { puts("bar"); } extern void foo(void); int main(void) { foo(); return 0; } foo.c #include <stdio.h> extern void bar(void); void foo(void) { puts("foo"); bar(); } I compile and run like: gcc -c -fpic foo.c gcc -shared -o libfoo.so foo.o gcc -L$(pwd) -o test main.c -lfoo ./test And I get the output I expect: foo bar However, I must use dlopen() and dlsym() because