1

Hello I am trying to create a C wrapper function for Python but I am having some trouble.

This is a simple test case that reproduces the problem. All the C function does is print the string given to it.

import ctypes
def test(hi):

    fun = ctypes.CDLL(r"\cygwin64\home\User\test\test.so")
    fun.print.argtypes = [ctype.c_char_p]

    fun.print(hi) 

test("pizza")

The error message I get is.

Traceback (most recent call last):
  File "C:\cygwin64\home\CCSS Student\test\kdtw.py", line 25, in <module>
    test('pizza')
  File "C:\cygwin64\home\CCSS Student\test\kdtw.py", line 19, in test
    fun = ctypes.CDLL(r"\cygwin64\home\CCSS Student\test\test.so")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line >364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

I have tried giving the full path (including drive) and the file name and this file is in the same directory. The C file compiles to the .so file. One note is that I am on Windows which could make a difference.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • 1
    Just one thing to watch out for, it may not be *that* file that it cannot find. You tend to get the same error if it depends on *another* file (such as cygwin.dll?). It may be worth running a dependency walker on your `.so` file to see if there's any unusual ones that may not be in your libpath (or Windows equivalent). This is assuming, of course, you've checked the path is correct for your immediate file. Might it need a windows path (including drive)? – paxdiablo Oct 30 '20 at 01:09
  • @paxdiablo I'll try the dependency walker though it only has and as its imports. How could I run a dependency walker? – Marc Johnson Oct 30 '20 at 01:24
  • See this answer (https://stackoverflow.com/a/18650202/235698) for using a tool to track down dependency issues as well. – Mark Tolonen Oct 30 '20 at 16:37
  • Aren't you trying to create a wrapper for C in Python? In any case, please search the error message online, it's not like it's too specific and you should be able to understand things easily. – Ulrich Eckhardt Oct 30 '20 at 18:05

0 Answers0