views:

180

answers:

1

I'm working on a 100% C project for which the windows port is compiled using visual studio 2008 express edition. My project uses a couple of linux libraries which I was able to statically compile using MingGW.

I'd like to know if it's safe to link my project to those libraries and what were the possible trouble I might encounter.

I could compile the libraries I'm using with visual studio, but this would be quite some work as they are based on autoconf and does not provide any project file.

I've already read this, this, this and this.

A: 

It's the "statically compiled" part that has me worried. If the libraries were compiled into DLLs then there is a good chance are that it will work, but as you're linking statically, the MINGW compiler will have made certain assumptions that are true regarding its runtime library but might or might not be true of the MSVC runtime library. Given that you're asking code compiled with one compiler to link against another compiler's RTL, there is a potential for mayhem there.

One advantage you have is that you're dealing with C here and not C++ - with a C++ library, you wouldn't stand a chance of this working, in C it just might. I would be very careful to ensure that structure alignment is the same across the compilers and just give it a try. If the linker complains about missing symbols then you've got your answer as to how compatible the RTLs really are, if it links OK, well, give it a try.

All of that said, I've worked on a C++ project which had one of the C libraries compiled with GCC (I think it was MINGW) for similar reasons that you mention. It did work, the software ran OK and had been used like this for quite a while. The main issue we had was that certain builds of the library would prevent the MSVC executable from being linked with debug information; careful tweaking of the MINGW command line fixed that problem.

Timo Geusch