c++ - 将参数传递到 C++ 共享库

标签 c++ linux shared-libraries visibility

我想将参数传递到 C++ 共享库 lib.so 形式的 loader.exe 中。

抱歉,请更新问题。

共享库如:

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

在loader.exe中,使用dlopen来加载它。

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

我想更改 loader.exe 中 num 的值。当我调用函数 count() 时,它可以给我新的结果。

我该怎么办?

谢谢!

最佳答案

您可以在加载程序中定义一个全局变量num(设置为所需的值)并进行更改

     int num = 9;

     extern int num;

.

关于c++ - 将参数传递到 C++ 共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17344286/

相关文章:

c++ - 为什么复制到的对象必须与复制自的对象具有相同的低级别常量?

c++ - C 中的函数序言和结尾

c - 多线程计算矩阵乘积的时间成本

c++ - const_reference_type 不编译但 const value_type& 编译

c++ - 使用 SIMD 将 10 位值打包成字节流

c++ - 在不同环境中正确使用 C 虚拟函数替换

c - 重定向时强制程序刷新其标准输出

php - 调用 php exec() 时未加载共享库

c++ - 关于 Unix 上共享库的困境

jenkins - 无法实例化 Jenkins 共享库中的对象