views:

74

answers:

2

I have libraries which are build using VC++. I want to use the same libraries in a program and build in cygwin gcc compiler. Is this scenario will work?

+1  A: 

Since C++ doesn't have a standardized ABI, and since Visual C++ and g++ in particular almost certainly have different ABIs, I don't think you can do this. Your only real option is to restrict yourself to C, not C++.

Edit: If all of the libraries that you're using are straight C (extern "C", in C++ terms), then you ought to be able to share libraries between compilers. (Otherwise, your Cygwin and MinGW apps couldn't call the Windows API.) You'll need to be careful to match up calling conventions. For example, the Windows API uses __stdcall instead of the standard C calling convention. You can tell GCC which calling convention to use with function attributes. Google, and your library's header files, should have more information on what calling convention to use.

Josh Kelley
Actually I want to use C-Language only. Is it possible?
Thangaraj
It's certainly easier with C, but the static lib format is still different.
Martin Beckett
Thanks buddy, Really this make sense. But when I try to compile my program, I am getting duplicate declaration errors. Do you have any clue how to rectify this error. Here the scenario is, the lib is already compiled. If I use this lib in VC environemnt I am able to compile the program without any issues. but in cygwin gcc I am getting duplicate declaration errors.
Thangaraj
@Martin: True, I assumed DLLs and was glossing over how to make those link properly. Thanks for the correction.
Josh Kelley
@hellothangam: Without seeing your code and the library, I'm not sure what to tell you. I know it ought to be possible in theory (if you're using a DLL), but I haven't done it before. Sorry.
Josh Kelley
A: 

Probably not

There is mingw a port of GCC (and lots of gnu tools) to windows which uses standard windows libs - it's pretty much a drop in replacement for cygwin and should be easier to link to gcc.

Martin Beckett
Actually not a drop-in replacement at all - Cygwin attempts to create a a Posix environment on top of windows - MinGW GCC is simply a normal Windows executable that makes no such attempt.
anon
@Neil Butterworth - true, using gcc in mingw is the same. But code written for a posix platform that builds with cygwin doesn't necessarily build with mingw, although most stuff will.
Martin Beckett