Cffibon Windows compile with dll instead of lib

212 views
Skip to first unread message

Chris De Boeck

unread,
May 22, 2021, 9:43:04 AM5/22/21
to python-cffi
Hello,

I'm trying to build a c module with cffi, but for some reason the compiler always looks for a .lib file instead of my .dll file (pcre2.dll):

    LINK : fatal error LNK1181: cannot open input file 'pcre2.lib'

Below is my code for the build (API mode):

    from cffi import FFI
    ffibuilder = FFI()
    
    ffibuilder.cdef("""
        char * mdtokenizer_build(char *text, struct mdtokenizer_info **token_info);
        void mdtokenizer_free(struct mdtokenizer_info **token_info);
    """)
    
    ffibuilder.set_source("_md_token", # name of the output C extension
    """
        #include "markdown.h"
        #include "nodelist.h"
        #include "regexapi.h"
        #include "regexfts.h"
        #include "pcre2.h"
        #include "pcre2posix.h"
    """,
        sources=['markdown.c', 'nodelist.c','regexapi.c','regexfts.c'],   
        libraries=['pcre2','pcre2posix'])    
    
    if __name__ == "__main__":
        ffibuilder.compile(verbose=True)

Is there any way to tell cffi to look for a dll instead of a lib.


thx

Armin Rigo

unread,
May 22, 2021, 1:53:54 PM5/22/21
to pytho...@googlegroups.com
Hi Chris,

On Sat, 22 May 2021 at 15:43, Chris De Boeck <chris.d...@gmail.com> wrote:
> I'm trying to build a c module with cffi, but for some reason the compiler always looks for a .lib file instead of my .dll file (pcre2.dll):
>
> LINK : fatal error LNK1181: cannot open input file 'pcre2.lib'
>
> Below is my code for the build (API mode):

This is a general question of how to build C programs on Windows. I
have limited experience myself, but as far as I know, the normal way
this is done on Windows is to install the .lib from the libraries that
you want to link with. In other words, it is common to require
'pcre2.lib' in order to compile a C program that calls 'pcre2.dll'. I
think I've read long ago that there is a hack that produces a .lib
from a .dll. Someone else might have more information for you, or
maybe google around. But yeah, I would recommend first looking for
'pcre2.lib'.


A bientôt,

Armin.

Matti Picus

unread,
May 23, 2021, 11:15:54 AM5/23/21
to python-cffi
The term to search for is "import library", and the linker requires one to link to a DLL on windows. This stack overflow answer seems to suggest a path to generate one from a DLL.


Matti
 

Chris De Boeck

unread,
May 23, 2021, 2:10:37 PM5/23/21
to python-cffi
Thx for the answers. 

I've built the dll myself with GCC, but I wasn't aware of the requirement of libs in windows.

I'll try with MSVC to build dll+lib

Greetings

Op zondag 23 mei 2021 om 17:15:54 UTC+2 schreef Matti Picus:
Reply all
Reply to author
Forward
0 new messages