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.?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

What different between DL and .SO
.SO is the equivalent of .DLL on Linux and similar systems. Both are implementations of shared libraries, but on the different platforms.
gcc --version gcc (MinGW.org GCC-6.3.0-1) 6.3.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "Is this what you mean " @marpor
Yes, did that work?
If you get the same error, it may also be because you are mixing 32- and 64-bit versions. If you are running 32-bit Python it will only load 32-bit DLLs. So make sure you get the same version of both Python and GCC.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.