• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Accessing global vars in an exe

I have an application on AIX that dynamically loads libraries at run-time (the executable is not linked to the libraries). Is it possible to access a global variable inside the executable, from the loaded library ? I tried declaring the global, then using "extern long glName;", and it compiles. But when I try to access it, my app crashes. P.S. my 'C' is quite rusty.

  • 2
1 Solution
Try this
1.c Your programm

long global_var=10;

long *get_globalvar(void)
      return (&global_var);

2.c your dll

long *pglobal_var=get_globalvar();

gbursonAuthor Commented:
Thanks for the response. I am trying to test it. Can you advise me on how to export the function name. I have declared it like,

long * getAppInfo(void);

but when I check the exported functions, its not there (I check using 'nm' as I am running on AIX).

Thanks again,
How do you export functions in a DLL under AIX?
You should be able to do the same with a global variable.
gbursonAuthor Commented:
I had the same problem originally with the global (it wasn't exported). I referenced it in some of the code, and then it was exported. Not true with the function. I have called it in the code, explicitly named it in an export file, used the linker option to export all symbols, and its still not there !

I must be missing something ...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now