0
  • Lately I have been working on Ctypes. I have a .C file let me call it ABC.C.
  • It has many functions I just need to call this Algorithm_Interface function in python using Ctypes.
  • I tried using gcc to create a .so(like a library file) file from geeks for geeks source .gcc -fPIC -shared -o libfun.so ABC.c
  • And by using that command , in the .C source file directory. A .so file is created(libfun.so).

In python I used this code to call that function:

import ctypes
f=open( "data.txt","r")
Raw_file=f.read()
fun = ctypes.CDLL("D:/NR/SPO2/libfun.so")
fun.Algorithm_Interface.argtypes = [ctypes.c_int]
returnVale = fun.Algorithm_Interface(Raw_file) 

While I try to run it it returns a error.

[WinError 193] %1 is not a valid Win32 application

how to solve this.?

1 Answers1

1

Windows uses .dll and .exe for applications. The .so is compiled for a different system (like Linux).

Python ctypes uses regular Windows functions by the looks of it, and thus also only support .dll.

You need a version of gcc that produce Windows binaries to compile your C source code before you can load it on Windows.

There's a lot of different distributions of GCC for Windows, like for example Mingw. Just google "GCC for Windows".

Once you have a Windows based GCC installed, use that in place of your current gcc, but use libfun.dll for in place of libfun.so.

marpor
  • 153
  • 3