How to link DLL to Visual studio code [duplicate] - c++

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'

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

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.

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.

Related

MSVC library linking with MinGW

I have dll libraries from specific SDK compiled with MSVC '08 while using MinGW. And yes, I've got undefined reference.
undefined reference to `Some::NameSpace::Here::Class::method()'
In my project I'm using MinGW comliler with Qt (just because I'm making cross-platform app) and Linux libraries provided with SDK works just fine.
1) I've tried using pexports tool as in mentioned in MinGW FAQ but got no success. Still same undefined reference (no changes in errors masseges).
In my .def file I've got lines like:
?Method#Class#Here#NameSpace#Some##QAE_NIIGW4eReturnType#234##Z
2) Also extern "C" wasn't helpful. I surrounded with it every SDK .h include where it was possible (one header contains template definitions, so I wasn't able to surround it).
Strange thing is, that instead of:
undefined reference to `_imp___ZN6IClass6Methodci'
I got:
undefined reference to `Some::NameSpace::Here::Class::method()'
In function `ZN11MyClass21MethodEv':
So I think I messed up with name mangling.

undefined references cygwin with stdcall-fixup

I'm building something using Cygwin 32 bit. It's quite large so it has a couple of header files defined in their own .cpp files. I'm even using a few c++ boost headers, linking them. I'm doing this on x64 Eclipse Luna. The project is comprised of a mix of C and C++ files. Every time I build the project I keep getting undefined references errors, for all functions in the header files, including those from boost, despite me having linked the boost libraries correctly. Unfortunately, I don't have enough reputation to attach a screenshot(doesn't make any sense). But below is a sample of the errors. I have even tried linking using option enable-stdcall-fixup to no avail.
./caches.o:caches.cpp:(.text+0x1957): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
./caches.o:caches.cpp:(.text$_ZNK5boost10filesystem16filesystem_error4whatEv[__ZNK5boost10filesystem16filesystem_error4whatEv]+0xa2): undefined reference to `boost::filesystem::path::codecvt()'
./fscore.o:fscore.cpp:(.text+0xa1): undefined reference to `btree_init()'
Please help.
Sincerely, batman

Cannot use LibHaru because cannot find the reference of zlib

I am trying to build a program that will hopefully create dynamic .pdf files. I have actually developed a similar project with PHP for web, but now I want to write it with C++.
This resulted me to rebuild those three libraries (zlib, libpng and libharu) more than time times for the last four days. I have read all the relevant entries in the web (including this stack overflow entry) I understood that my problem is that the compiler cannot find zlib (maybe I understood the problem wrongly)
I want to explain what I've done. Please note that I'm using Codeblocks IDE with GNU GCC C++ Compiler (MingGW) in Windows 7. First, I compiled zlib 1.2.7 and created my zlib.a static library file (I'm using static libraries). Secondly, I compiled libpng 1.5.13 and created my libpng.a. Thirdly, I compiled libharu (snapshot) and created my libharu.a static library file. Then I added those library files to my project. (I did everything explained in here). And at last, compiled my project.
Well, I shall say I did those all steps more than ten times, changing some small things, but everytime I am getting an error. I have even tried the official examples in libharu.org.
The most weird thing is that my error is NOT stable. Nearly everytime I got different errors! But mostly it was related with hpdf_streams.c.
My recent log file:
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xd4a): undefined reference to `deflateInit_'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xdfa): undefined reference to `deflate'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xe78): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xee2): undefined reference to `deflate'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xf7e): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xfb7): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xff1): undefined reference to `deflateEnd'
We just had this issue. You need to recompile zlib with WIN_API off. Or use the dll's and not the static library.

Cygwin Compiler: Undefined Reference

When I try to compile a random project in Code:Blocks, the Cygwin Compiler throws an undefined reference error about own library files:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(_cygwin_crt0_common.o):_cygwin_crt0_common.cc:(.data+0x0):
undefined reference to `___real__Znwj'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(_cygwin_crt0_common.o):_cygwin_crt0_common.cc:(.data+0x8):
undefined reference to `___real__ZdlPv'
I am linking the netlink library as well as the WS2_32.lib
Is that a compiler issue?
Other hint, it comes from _cygwin_crt0_common.cc. So there is obviously central something missing. You are using Cygwin version of gcc, right? Have your tried -lcygwin? You could also try -mno-cygwin.
My advice is normally to use vanilla MinGW, creates clean windows binaries (at the loss of POSIX features)..

cross compiling qt (linux/mingw -> windows): various undefined references

(Crosspost from here, since nobody seems to have an idea)
Hello everyone,
I am trying to cross compile qt 4.8.3 from my linux for my windows. The final goal is to build a static qt, but independent of building static or not I always get the same error. Playing around with various flags didn't help either:
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x18dc): undefined reference to `QGb18030Codec::QGb18030Codec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x18ef): undefined reference to `QGbkCodec::QGbkCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1902): undefined reference to `QGb2312Codec::QGb2312Codec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1915): undefined reference to `QEucJpCodec::QEucJpCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1928): undefined reference to `QJisCodec::QJisCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x193b): undefined reference to `QSjisCodec::QSjisCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1956): undefined reference to `vtable for QEucKrCodec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1971): undefined reference to `vtable for QCP949Codec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x198c): undefined reference to `vtable for QBig5Codec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x19a7): undefined reference to `vtable for QBig5hkscsCodec'
I'm using the default win32-g++ configuration file in combination with mingw.
I googled quite a bit around, but I have still no idea, where this comes from.. Maybe someone of you has the right hint for me ;-)
You could use MXE to build it. It's quite easy. You simply do:
make qt
It does pretty much everything automatically, including downloading sources, applying needed patches to enable cross compiling (which might be why manually cross compiling Qt on your own is failing), and building all dependencies. You can download MXE from: http://mxe.cc. Read the docs of course on how to cross compile software with it.
The gist of it is that instead of qmake you use i686-pc-mingw32-qmake (after you've changed your PATH to include the MXE directory, as per the docs.)
MXE builds everything as static libraries, so when you cross compile a program, you'll get a single .exe file with no depenendies on any DLLs.