I can't mix VC & GCC

I compile a 'cpp' file with the g++ (or gcc with -x c++ option) to obtain a .obj file, then I compile the remaining with VC and I have this linking error:

main.obj : error LNK2019: simbolo externo "void __cdecl fmulGCC(float *,float *)" ( fmulGCC@@YAXPAM0@Z) sin resolver al que se hace referencia en la funcion _main
fmul_GCC.obj : error LNK2019: simbolo externo __ZdlPv sin resolver al que se hace referencia en la funcion __Z7fmulGCCPfS_
fmul_GCC.obj : error LNK2019: simbolo externo __Znaj sin resolver al que se hace referencia en la funcion __Z7fmulGCCPfS_
Debug/mulfloat.exe : fatal error LNK1120: 3 externos sin resolver

With 'c' code it works, so I think that is for c++ function naming problem, the fmulGCC@@YAXPAM0@Z that generates VC is not equal in g++ (GCC).

The problem is that I can't be limited to C code if I want to mix, because it haven't Classes.

I have tried the option '-std=xxx' with the c++ options, and it don't work yet. Anyone knows a solution to this .

Thanks.


Answer this question

I can't mix VC & GCC

  • vmehta

    GCC has a secondary use for its __asm__ keyword: overriding the linker-level symbol for an identifier.  For example,

    void myfunction(void) __asm__("@realname@");

    Unfortunately, you can't use GCC's __asm__ to do what you need as GCC's assembler backend rejects the character used on Visual C++'s name mangling.  Considering that this assembler is targeted at Win32, where has always been a legal identifier character at the linker level, this can be considered a bug.

    It is a shame that Visual C++ does not have a comparable feature to this particular use of __asm__.  Something like __declspec(symbol, "name") would be really nice.  At work we have an .obj parser that basically hex-edits the compiler-chosen name in an already-compiled file to get around this Visual C++ limitation.


  • j.oneill

    It is for a simple mix between codes for GCC and for VC, for example I have a code that uses inline GCC type and I don't want to rewrite it to VC type, and I can't compile managed (Framework) code in GCC because it is not compatible (I think), and I like to compile DirectX code with the MS compiler, but if I take a code (math calculations, etc.) made by GNU community usually are for compile with the GCC.

    For that my interest in mixing them. Maybe it would be a god idea that MS and the GNU community do the compilers compatible at this level, for C++ because for C are compatible now.

    Compiling an entire project with GCC can be bad for stress :)

  • _dog

    Feel free to log such suggestion at http://lab.msdn.microsoft.com/productfeedback/default.aspx

    Thanks,
      Ayman Shoukry
      VC++ Team

  • TirthankarDutta

    BTW, you can always log suggestion issues at http://lab.msdn.microsoft.com/productfeedback/default.aspx

    Thanks,
      Ayman Shoukry
      VC++ Team

  • axedeveloper

    I don't believe this is a supported scenario. Why not compile all with VC or all Gcc

    Name decorations will be different in such cases.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • -bc-

    This is actually a C++ problem, not a GCC problem of a Visual C++ problem.  The C++ standards committee did not bother standardizing on a name mangling convention, so 2 fully compliant C++ compilers (of which neither VC++ nor GCC is Smile) cannot actually link C++ code together.  If you need/want to be able to do this, you have to flatten all your interfaces as C, then link.  While it's not particularly easy, it's really the only officially supported way of doing anything.

    -Kev

  • I can't mix VC & GCC