Accessing main program global variables from a dlopen()ed dynamic library in C on OS X

后端 未结 2 1051
天涯浪人
天涯浪人 2020-12-15 01:05

I am maintaining a small application that has some plugin-like functionality, which is implemented through runtime-loaded dynamic modules.

Specifically, since it\'s

2条回答
  •  無奈伤痛
    2020-12-15 01:54

    Put the global in main.c and declare it extern in the shared object, and try this:

    MACOSX_DEPLOYMENT_TARGET=10.3 ld -dylib -undefined dynamic_lookup -o multiply.so multiply.o
    

    or

    MACOSX_DEPLOYMENT_TARGET=10.3 libtool -dynamic -undefined dynamic_lookup -o multiply.so multiply.o
    

    It worked for me on Mac OS X 10.4

提交回复
热议问题