Ctypes is able to load .so files until I use one that has pthread_create() in it's source code. Then it gives the error: """
FileNotFoundError: Could not find module '\the_path_to_module\module_name' (or one of it's dependencies). Try using the full path with constructor syntax.
"""
I'm using the full path and it works fine until I put pthread functions in the source code. I am able to still load it if pthread_t variables are declared, but soon as pthread_create() is coded in, ctypes refuses to load it.
I'm able to run standalone exe files using pthread just fine. I'm using Windows 10 and Python 3.10
Here's basically what I have coded that throws the error:
C code in the .so file:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
// I can include pthread.h and declare pthread_t variables and ctypes will load the file
void some_func(args){
pthread_t th_1, th_2, th_3, th_4;
void* func_to_use_in_threads(void *arg)
{stuff in function}
// But as soon as I include pthread_create() in the code, Python ctypes won't load it
pthread_create(&th_1,NULL,func_to_use_in_threads,&arg);
pthread_create etc
pthread join() etc
.........}
So anyway the error says some dependency is missing, but like I said when I write pthread standalone .exe's there is no problem.
I have tried many things when compiling at this point and always the same error when trying to load with ctypes. I don't know much about compiling and linking and am not even sure if this is the problem so I need help.
The basic compile code I've used is: gcc -fPIC -shared -o the_name.so the_name.c -lpthread
But I've gone so far as to copy all the files that pthread.h has listed as #include into a directory and type them in like this: gcc -fPIC -shared -o -the_name.so -the_name.c -B (directory) errno.h limits.h process.h pthread.h signal.h timeb.h types.h libwinpthread-1.dll
I don't really know what I'm doing with the compiling and linking like this, but it did compile, and ctypes still threw the same error.
The Python code is basically:
import ctypes
some_lib=ctypes.CDLL('file_path\\file_name.so') #won't load the file
I also did: ` import ctypes import os
some_lib=ctypes.CDLL(os.path.join('filepath/filename.so')) #same error`
Can anyone help?