- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想做的是从 Python 调用 C++ 方法以返回二维数组。 Python 文件名为:BaxterArm1.py,C++ 文件名为:baxIK.cpp。下面是我如何编译我的 C++ 程序:
g++ -c -fPIC baxIK.cpp -o baxIK.o
g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o
下面是C++程序的相关部分:
int main(int argc, char** argv)
{
}
extern "C" float** compute(float x, float y, float z, float q1, float q2, float q3, float q4)
{
unsigned int num_of_solutions = (int)solutions.GetNumSolutions();
std::vector<IKREAL_TYPE> solvalues(num_of_joints);
float** sols;
sols = new float*[(int)num_of_solutions];
for(std::size_t i = 0; i < num_of_solutions; ++i) {
sols[i] = new float[7];
for( std::size_t j = 0; j < solvalues.size(); ++j)
{
printf("%.15f, ", solvalues[j]);
sols[i][j] = solvalues[j];
}
printf("\n");
}
return sols;
}
思路是返回一个Nx7的数组供Python接收。 Python代码如下:
def sendArm(xGoal, yGoal, zGoal, right, lj):
print "Goals %f %f %f" % (xGoal, yGoal, zGoal)
output = ctypes.CDLL(os.path.dirname('baxIK.so'))
output.compute.restype = POINTER(c_float)
output.compute.argtypes = [c_float, c_float, c_float, c_float, c_float, c_float, c_float]
res = output.compute(xGoal, yGoal, zGoal, 0.707, 0, 0.7, 0)
print(res)
我得到的错误在线
output.compute.restype = POINTER(c_float)
回溯如下:
File "/home/eadom/ros_ws/src/baxter_examples/scripts/BaxterArm1.py", line 60, in sendArm
output.compute.restype = POINTER(c_float)
File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: python: undefined symbol: compute
我对如何解决这个问题感到困惑。另外,有人可以检查一下,看看我是否正确发送了二维数组?因为它只发送一维数组,但我在发送二维数组时找不到任何东西。我很感激任何帮助。
最佳答案
终于成功了!问题是 (os.path.dirname('baxIK.so')
返回一个空字符串,所以我放入了完整目录。我通过使用 llapack 编译 g++ 解决了我之前提到的另一个问题现在我正在修复最后一个细节。我希望这对其他人有帮助。
关于python - 属性错误 : python: undefined symbol: when accessing C++ function from Python using ctypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33908356/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!