Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking *.lib files with MinGW

Tags:

mingw

linker

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'
like image 361
Alecs Avatar asked Aug 30 '11 09:08

Alecs


People also ask

Can MinGW link .LIB files?

a from MinGW. Since the MinGW makefile creates an import library in MSVC's lib format, the produced shared library (DLL) can be used from both MinGW and Microsoft Visual Studio with no further adaption. Just link to the import library FreeImage. lib from either MinGW or Microsoft Visual Studio.

How do I open .LIB files?

To load the LIB file, select File → Load Library..., navigate to the location of your LIB file, select the file, and click Open.

What are .LIB files?

A lib file is just a collection of related obj files, much like putting obj files in a directory. That is essentially what a lib file is, a library of obj files. For a static link, all of the obj files that an executable uses are combined into one file.


3 Answers

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

like image 63
Sasha Avatar answered Sep 19 '22 14:09

Sasha


New mingw versions support linking lib files. But I faced issues where .lib is with prefix libxxxx.lib.It ommits the preffix 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.

like image 42
Chand Priyankara Avatar answered Sep 22 '22 14:09

Chand Priyankara


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.

like image 39
Marco van de Voort Avatar answered Sep 22 '22 14:09

Marco van de Voort