0

I want to pass an argument into a C++ shared library lib.so form loader.exe.

Sorry, update the question.

shared library like:

int count(){
         int num = 9;
         int result = 0;
         for ( int i = 0; i < num; i++ ){
                 result ++;
         }
         return result;
}

In the loader.exe, use a dlopen to load it.

void *handler = dlopen("lib.so", RTLD_LAZY);

I want to change the value of num from loader.exe. when I call the function count(), it can give me the new result.

How should I do?

thanks!

user2413399
  • 85
  • 1
  • 1
  • 5

1 Answers1

0

You can define a global variable num (set to the desired value) in your loader program and change

     int num = 9;

to

     extern int num;

.

Armali
  • 18,255
  • 14
  • 57
  • 171