Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AttributeError:python:未定义符号:访问C++;使用ctypes的Python函数 我想做的是调用Python中的C++方法返回一个2D数组。Python文件名是:BaxTeARM1.Py和C++文件名是:Baxk.CPP。下面是我如何编译我的C++程序: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; } 是C++程序的相关部分: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; }_Python_C++_Numpy_Multidimensional Array_Ctypes - Fatal编程技术网

AttributeError:python:未定义符号:访问C++;使用ctypes的Python函数 我想做的是调用Python中的C++方法返回一个2D数组。Python文件名是:BaxTeARM1.Py和C++文件名是:Baxk.CPP。下面是我如何编译我的C++程序: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; } 是C++程序的相关部分: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; }

AttributeError:python:未定义符号:访问C++;使用ctypes的Python函数 我想做的是调用Python中的C++方法返回一个2D数组。Python文件名是:BaxTeARM1.Py和C++文件名是:Baxk.CPP。下面是我如何编译我的C++程序: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; } 是C++程序的相关部分: g++ -c -fPIC baxIK.cpp -o baxIK.o g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o 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; },python,c++,numpy,multidimensional-array,ctypes,Python,C++,Numpy,Multidimensional Array,Ctypes,我得到的错误是在线的 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 37

我得到的错误是在线的

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

我不知道该怎么解决这个问题。还有,有人能检查一下这个,看看我是否正确发送了2D数组吗?实际上,它只发送了一个一维数组,但我在发送二维数组时找不到任何东西。我非常感谢您的帮助。

终于让它工作了!问题是
(os.path.dirname('baxIK.so')
返回了一个空字符串,所以我把它放在了完整的目录中。我通过使用llapack编译g++修复了前面提到的另一个问题,现在我正在修复最后一个细节。我希望这对其他人有所帮助。

终于让它工作起来了!问题是
(os.path.dirname('baxIK.so'))
返回一个空字符串,因此我将其放入完整目录。我通过使用llapack编译g++修复了前面提到的另一个问题,现在我正在修复最后一个细节。我希望这对其他人有所帮助。

返回类型是指向指针的指针。您是否尝试过
output.compute.restype=pointer(指针(c_float))
是的,我会更改。谢谢。但这并不能解决您使用外部“C”的其他问题,因此它不应该被名称损坏。请检查是否为“计算”在
objdump-T baxIK.so
中列出,即在
dlsym
查找它的动态符号表中。我刚刚这样做了。Compute显示一次,但整个终端输出太长,终端无法容纳。还有其他建议吗?
objdump-T baxIK.so | grep Compute
返回类型是指针指向指针的。您尝试过吗
output.compute.restype=POINTER(POINTER(c_float))
Ah true,我会更改它。谢谢。但这并不能解决其他问题。您正在使用外部“c”,所以它不应该被名称弄乱。检查是否“compute”在
objdump-T baxIK.so
中列出,即在
dlsym
查找它的动态符号表中。我刚刚这样做了。Compute显示一次,但整个终端输出太长,终端无法容纳。还有其他建议吗?
objdump-T baxIK.so | grep Compute
在POSIX系统上
CDLL(“”)
引用了主模块。由于未定义的符号错误,我甚至没有注意到您错误地使用了
dirname
。如果文件与脚本/模块位于同一目录中,您可以使用
scriptdir=os.path.abspath(os.path.dirname(_u文件_u));
libpath=os.path.join(scriptdir,'baxIK.so'))
。在POSIX系统上
CDLL(“”)
引用了主模块。由于未定义的符号错误,我甚至没有注意到您错误地使用了
dirname
。如果文件与脚本/模块位于同一目录中,则可以使用
scriptdir=os.path.abspath(os.path.dirname(\u file\uuuu));
libpath=os.path.join(scriptdir,'baxIK.so')