Related : [[C]] [[CPlusPlus]] [[GCC]] [[Cygwin]] [[MSVC]] Mixing compiled objects between [[GCC]] and [[MSVC]] does work at least when shared code is in [[C]], [[C++]] is causing trouble on different name mangeling. ===Sample code=== cat cplusplus.h << EOF #ifndef CPlusPlus_h_ #define CPlusPlus_h_ #define API class API CPlusPlus { public: static int f(int in); }; extern "C" { API int fglobal(int in); API CPlusPlus* getInstanceCPlusPlus(); } #endif EOF cat cplusplus.cpp << EOF #include "cplusplus.h" int CPlusPlus::f(int in) { return in; } int fglobal(int in) { return in; } EOF cat main.cpp << EOF #include #include using namespace std; #include "cplusplus.h" int main(int argc,char* argv[[]]) { cout << "# " <f(argc) << endl; // printf("# %d\n", getInstanceCppModule()->f(argc) ); #endif // @see http://cygwin.com/ml/cygwin/2005-03/msg00413.html return EXIT_SUCCESS; } EOF ===Static lib link :=== g++ -c -o ./cplusplus.o -mno-cygwin -mwindows -g -I. -Dcygwin -D_GNU_SOURCE -I. ./cplusplus.cpp ar rcu ./libcplusplus.lib cplusplus.o cl.exe /c /EHsc /nologo main.cpp link.exe \ /INCREMENTAL /NOLOGO /MACHINE:X86 /DEBUG /SUBSYSTEM:CONSOLE \ /OUT:"cplusplus.exe" /LIBPATH:"." main.obj libcplusplus.lib cplusplus.exe * # 15 ldd cplusplus.exe h:/src/cplusplus/cplusplus.exe C:\WINDOWS\System32\KERNEL32.dll C:\WINDOWS\System32\ntdll.dll ===Static lib with C++ method=== rm main.obj cl.exe /c /EHsc /nologo /DBUG main.cpp cc-msvc.sh link.exe \ /INCREMENTAL /NOLOGO /MACHINE:X86 /DEBUG /SUBSYSTEM:CONSOLE \ /OUT:"cplusplus.exe" /LIBPATH:"." main.obj libcplusplus.lib main.obj : error LNK2019: unresolved external symbol "public: static int __cdecl CPlusPlus::f(int)" (?f@CPlusPlus@@SAHH@Z) referenced in function _main cplusplus.exe : | error LNK1120: 1 unresolved externals nm libcplusplus.lib ; cplusplus.o: 00000000 b .bss 00000000 d .data 00000000 N .stab 00000000 N .stabstr 00000000 t .text 00000000 T __ZN9CPlusPlus1fEi 00000008 T _fglobal For obscure reasons, the mangling name are different ===Conclusion=== So Why it is impossible to link [[C++]] [[GCC]]'s objects coming with [[MSVC]] ? http://cygwin.com/ml/cygwin/2005-03/msg00413.html Can dynamic libs workaround this ? I doubt [[GCC]] can write a compatible [[MSVC]] "library stub" ( XYZ.lib that goes along XYZ.dll, not a static one : libXYZ.lib ) But maybe runtime linking is possible ... I am investigating on this... [[ToDo]] ===MISC=== Thanks go to : Arend-Jan Westhoff, Christopher Faylor, Jonathan Arnold, Tim Prince and all the [[Cygwin]] pple. Some additional info: