25

Is it possible to Link *.lib files with MinGW (I use it with Eclipse)?

I'm fighting with libcurl+OpenSSL and I don't understand if my errors are because I try to use .lib-files in MinGW or something else is wrong:

..\lib/libeay32.lib(tmp32/asn_mime.obj):(.text[_SMIME_text]+0x6): undefined reference to `_chkstk'
..\lib/libeay32.lib(tmp32/asn_mime.obj):(.text[_SMIME_text]+0xb): undefined reference to `__security_cookie'
..\lib/libeay32.lib(tmp32/asn_mime.obj):(.text[_SMIME_text]+0x63): undefined reference to `@__security_check_cookie@4'
..\lib/libeay32.lib(tmp32/asn_mime.obj):(.text[_SMIME_text]+0x19e): undefined reference to `@__security_check_cookie@4'
..\lib/libeay32.lib(tmp32/ech_ossl.obj):(.text[_ecdh_compute_key]+0x6): undefined    reference to `_chkstk'
..\lib/libeay32.lib(tmp32/bio_asn1.obj):(.text[_asn1_bio_set_ex]+0x6): undefined reference to `_chkstk'
..\lib/libeay32.lib(tmp32/bio_asn1.obj):(.text[_asn1_bio_get_ex]+0x6): undefined reference to `_chkstk'
..\lib/libeay32.lib(tmp32/bio_asn1.obj):(.text[_BIO_asn1_set_prefix]+0x6): undefined reference to `_chkstk'
..\lib/libeay32.lib(tmp32/bio_asn1.obj):(.text[_BIO_asn1_get_prefix]+0x6): undefined reference to `_chkstk'
..\lib/libeay32.lib(tmp32/bio_asn1.obj):(.text[_BIO_asn1_set_suffix]+0x6): more undefined references to `_chkstk' follow
..\lib/ssleay32.lib(tmp32/ssl_lib.obj):(.text[_SSL_has_matching_session_id]+0xb): undefined reference to `__security_cookie'
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Alecs
  • 2,256
  • 8
  • 32
  • 45

3 Answers3

36

mingw also accepts libraries with a .lib extension.

For instance, a library named libsample.lib must be linked as

-L -llibsample

Reference: http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use

Sasha
  • 369
  • 3
  • 3
  • @Shasha Could you please help me out? I posted this question : http://stackoverflow.com/questions/38584344/linking-a-lib-file-on-windows-7 – lads Jul 26 '16 at 09:09
23

New mingw versions support linking lib files. But I faced issues where .lib is with prefix libxxxx.lib. It omits the prefix lib in linking. So make it like lib<name>.lib

Also there are ways to convert a .lib to .a ex: lib2a You can use that as well.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chand Priyankara
  • 6,739
  • 2
  • 40
  • 63
8

Probably not. mingw's static library format is *.a.

Dynamic libraries for a given platform are standardized by the OS loader that must be able to load them.

Static libraries only have to be understood by the toolchain's linker, and are thus less cross compiler compatible. Afaik *.lib files are not even compatible across all MSVC versions.

Added later due to pestering comments: Newer versions of mingw also support .lib files, but you asked your question back in '11, and then you probably wouldn't have them then.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
  • 5
    For the downvotes: please take note that this answer is written significantly *before* the other answers. – Marco van de Voort Apr 13 '16 at 07:06
  • 1
    As it is obviously outdated, you should probably consider adapting your answer. That would spare you more down votes and help people find the correct answer to their personal problem. – pogojotz Nov 30 '18 at 21:01
  • 1
    That would make the answer not in question to the question. If you think the thread is dated or confusing, vote to close it, and vote a more recent one up. – Marco van de Voort Jan 23 '19 at 15:30
  • I don't think the thread is dated at all, just your answer. "Probably not." is just not correct anymore (for quite some time already), see Sasha's answer, which should be the accepted one. But hey, that are your downvotes, do as you like ;) – pogojotz Jan 24 '19 at 13:38