Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Accessing global vars in an exe

Posted on 1999-08-03
Medium Priority
Last Modified: 2010-04-15
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.

Question by:gburson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 10

Accepted Solution

rbr earned 400 total points
ID: 1264171
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();


Author Comment

ID: 1264172
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,
LVL 11

Expert Comment

ID: 1264173
How do you export functions in a DLL under AIX?
You should be able to do the same with a global variable.

Author Comment

ID: 1264174
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 ...


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question