[Python] Using python CDLL to load dll, but no function from c code show up

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to import function written in c code into python. A minimal example I have tried is

    //test.h
    __declspec(dllexport) int HW(int, int);


    //test.c
    #include <stdio.h>
    #include <stdlib.h>
    #include "test.h"

    __declspec(dllexport) int HW(int a, int b)
    {
    return a + b;
    }


    I also tried to remove the __declspec(dllexport) in either files. Then I did the following in Visual Studio 2019 CMD

    cl /LD test.c


    or

    cl /LD test.c \libs\python37.lib


    In python I did

    from ctypes import *
    a = CDLL('test.dll')


    It turns out that HW is not an attribute of a. Which part did I do wrong?

    Continue reading...

Compartilhe esta Página