使用dlsym导入的函数中的参数位置错误 [英] Wrong arguments position in function imported with dlsym

查看:1095
本文介绍了使用dlsym导入的函数中的参数位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。当我使用共享库中的参数调用导入的方法时,在这些方法中我有错误的参数。它就像:

I have strange issue. When I invoking imported method with arguments from shared library, in those method I have wrong arguments. It's like:

x = 1; y = 2; z = 3;
(*method)(x,y,z);

在方法中我有:

void method(int x, int y, int z){
    // x = 2, y = 3, z = 32432423 - something like this
}

这里我如何导入:

QVector<int> (*interpolateValue)( int, int, int );
libHandle = dlopen( "plugins/libinterpolate.so", RTLD_LAZY );
*(void **)(&interpolateValue) = dlsym( libHandle, "_ZN11Interpolate16interpolateValueEiii" );

QVector<int> ys = (*interpolateValue)( lastY, newY, step );

我以这种方式进行了工作:

I made work around about this in such way:

QVector<int> (*interpolateValue)( int*, int, int, int );
QVector<int> ys = (*interpolateValue)( NULL, lastY, newY, step );

但我认为这不是一种手段。

But i think it's not a means.

推荐答案

c ++ filt(1) 说:

$ c++filt _ZN11Interpolate16interpolateValueEiii
Interpolate::interpolateValue(int, int, int)

这似乎表明函数你试图调用是一个C ++类的成员函数。这意味着它有一个隐式的第一个参数 - this 指针。您的解决方法修复了一些问题,因为您要传递 NULL 这个指针。显然,它根本不使用该参数。

which seems to indicate that the function you're trying to call is a member function of a C++ class. That means it has an implicit first parameter - the this pointer. Your workaround fixes things because you're passing a NULL this pointer for the method to use. Apparently it does not, in fact, use that parameter at all, though..

如果你不想以这种方式解决问题,请改变 Interpolate :: interpolateValue(int,int,int)成为一个自由函数,而不是它的任何类的方法。

If you don't want to have to work around the problem in this way, change Interpolate::interpolateValue(int, int, int) to be a free function instead of a method of whatever class it's in.

这篇关于使用dlsym导入的函数中的参数位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆