Is it possible to use the compiled gcc library with MSVC?

I have a project that relies on libiconv for several operations.

I used the precompiled binaries for iconv.lib for Visual Studio 2008, but now I had to switch to Visual Studio 2010 and there were no more precompiled binaries.

I decided to compile it myself, but as the libiconv documentation libiconv , there is no official support for MSVC compilers. However, I read somewhere that gcc can generate static libraries that were binary compatible with MSVC compilers if the binary interface remains in C Although it sounded crazy, I tried, and it almost worked.

I compiled it, renamed libiconv.a to iconv.lib and tried to link it. (If this is a bad idea, let me know).

First I ran into a link error:

 1>iconv.lib(iconv.o) : error LNK2001: unresolved external symbol ___chkstk 

After some research, I recompiled libiconv (on both versions of x86 and x64) by adding the -static-libgcc .

This worked, but only for my x64 version. An x86 release always fails with the same error.

What should I do to make this work?

+4
source share
1 answer

Yes, this is possible because if you compile strictly as a C interface, iconv will refer to msvcrt.lib , which is the Windows C runtime (strictly C, similar to glibc used by GCC). If you built it using the regular CCC GCC compiler, it will refer to libstdc++ and also call mangle differently from VC ++, which refers to msvcr.dll .

In your case, __chkstk is a check stack function (part of the C runtime), a function that is injected into each function call for verification. I'm not sure how to solve this “good” way, but you can change your build options for iconv to build with an additional compiler flag and suppress this check: /Gs999999


However, I created libiconv with Visual C ++ 2005/2008/2010, and the software that I built on it works fine (software used by military institutions if you need trust). I remember that it was a little annoying to create using the VC ++ compiler, but that should not be too much pain.

+3
source

All Articles