0

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.

Jay Chung
  • 175
  • 1
  • 1
  • 11
  • 2
    Instead of trying to describe your problem in text, you should show some code, most importantly *how* you `#define` the name. – Some programmer dude Sep 24 '14 at 07:22
  • Explain which library are you dynamically loading with `dlopen` and how and why you are using `dlsym` (on which particular symbol). Please *edit your question* to improve it (it is unclear). – Basile Starynkevitch Sep 24 '14 at 07:26
  • 1
    Oh, you mean that the external library was compiled with a macro and you want to use that macro too? Then that's not possible. Macros are not actually part of the of the compiled code, instead the preprocessor *replaces* macros with the actual code, the macros themselves leave no trace in the compiled code. – Some programmer dude Sep 24 '14 at 07:33
  • ah ok. this is a bit troubling because i have all different kinds of log funcitons such as warningLog, errorLog, criticalLog that are all #defined. – Jay Chung Sep 24 '14 at 07:37

1 Answers1

2

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)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547