Search code examples
cdlopen

using #defined function names as an input to dlsym


I have to use dlsym to load a function name from an external library.

But my concern is that he function is defined via a macro #define.

Assuming that dlopen call was successful, will dlsym find the correct symbol using the #defined name in this case?

The following is a header file which includes the #defined function name:

#define LogVPrintDebug(context, fmt, args)    \
       (void) LogVPrint(context, kLevel_Debug, fmt, args)

LogErr LogVPrint_(LogContext context, LogLevel level,
    const char* fmt, va_list args) __attribute__ ((deprecated));

and LogVPrint is the actual funciton.


Solution

  • Of course dlsym cannot find a #define-d symbol, since the C compiler is starting by its preprocessing phase which is expanding previously #define-d macros. So when the code using that name has been compiled, the preprocessed name is used (and only that name occurs in the shared object)