Link errors : InterlockedBitTestAndComplement, MemoryBarrier, RtlSecureZeroMemory

Well, I rarely ever post for help but I am at a complete loss, and am not sure if anyone can really even help with this problem.

Anyways, here it goes:

I have written a ruby extension which compiles and runs fine on Mac OS X and several *nix systems.

I have been working on porting it to a windows system. It currently compiles fine, but completely craps out on the linking stage.

Here is a paste of what happens: (using Visual Studio Express command line tools)

Compilation: straightforward, no issues, but here it is anyways:
[code]
Z:\rubysound\ext\rubysound>nmake

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tccommon.c
common.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcmain.c
main.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_channel.c
rubysound_channel.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_channelGroup.c
rubysound_channelGroup.c
z:\rubysound\ext\rubysound\rubysound_channelgroup.c(6) : warning C4700: uninitia
lized local variable 'channelGroup' used
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_constants.c
rubysound_constants.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_dsp.c
rubysound_dsp.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_geometry.c
rubysound_geometry.c
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_sound.c
rubysound_sound.c
z:\rubysound\ext\rubysound\rubysound_sound.c(10) : warning C4700: uninitialized
local variable 'sound' used
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_system.c
rubysound_system.c
z:\rubysound\ext\rubysound\rubysound_system.c(241) : warning C4700: uninitialize
d local variable 'resamplemethod' used
z:\rubysound\ext\rubysound\rubysound_system.c(241) : warning C4700: uninitialize
d local variable 'format' used
cl -nologo -I"C:/Program Files/FMOD SoundSystem/FMOD Programmers API/api
/inc" -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.8/i386-mswin3
2 -I. -c -Tcrubysound_vector.c
rubysound_vector.c

[/code]

and now the linking process, which just blows up:
[code]
cl -nologo -LD -Ferubysound.so common.obj main.obj rubysound_channel.obj
rubysound_channelGroup.obj rubysound_constants.obj rubysound_dsp.obj rubysound_
geometry.obj rubysound_sound.obj rubysound_system.obj rubysound_vector.obj msvcr
t-ruby18.lib oldnames.lib user32.lib advapi32.lib wsock32.lib "C:/Program File
s/FMOD SoundSystem/FMOD Programmers API/api/lib/fmodex_vc.lib" -lstdc++
-link -incremental:no -debug -opt:ref -opt:icf -dll -libpath:"c:/ruby/lib" -def
:rubysound-i386-mswin32.def -implib:rubysound-i386-mswin32.lib -pdb:rubysound-i3
86-mswin32.pdb
cl : Command line warning D9002 : ignoring unknown option '-lstdc++'
main.obj : error LNK2005: _InterlockedBitTestAndComplement already defined in co
mmon.obj
main.obj : error LNK2005: _MemoryBarrier already defined in common.obj
main.obj : error LNK2005: _RtlSecureZeroMemory already defined in common.obj
rubysound_channel.obj : error LNK2005: _InterlockedBitTestAndComplement already
defined in common.obj
rubysound_channel.obj : error LNK2005: _MemoryBarrier already defined in common.
obj
rubysound_channel.obj : error LNK2005: _RtlSecureZeroMemory already defined in c
ommon.obj
rubysound_channelGroup.obj : error LNK2005: _InterlockedBitTestAndComplement alr
eady defined in common.obj
rubysound_channelGroup.obj : error LNK2005: _MemoryBarrier already defined in co
mmon.obj
rubysound_channelGroup.obj : error LNK2005: _RtlSecureZeroMemory already defined
in common.obj
rubysound_constants.obj : error LNK2005: _InterlockedBitTestAndComplement alread
y defined in common.obj
rubysound_constants.obj : error LNK2005: _MemoryBarrier already defined in commo
n.obj
rubysound_constants.obj : error LNK2005: _RtlSecureZeroMemory already defined in
common.obj
rubysound_dsp.obj : error LNK2005: _InterlockedBitTestAndComplement already defi
ned in common.obj
rubysound_dsp.obj : error LNK2005: _MemoryBarrier already defined in common.obj
rubysound_dsp.obj : error LNK2005: _RtlSecureZeroMemory already defined in commo
n.obj
rubysound_geometry.obj : error LNK2005: _InterlockedBitTestAndComplement already
defined in common.obj
rubysound_geometry.obj : error LNK2005: _MemoryBarrier already defined in common
.obj
rubysound_geometry.obj : error LNK2005: _RtlSecureZeroMemory already defined in
common.obj
rubysound_sound.obj : error LNK2005: _InterlockedBitTestAndComplement already de
fined in common.obj
rubysound_sound.obj : error LNK2005: _MemoryBarrier already defined in common.ob
j
rubysound_sound.obj : error LNK2005: _RtlSecureZeroMemory already defined in com
mon.obj
rubysound_system.obj : error LNK2005: _InterlockedBitTestAndComplement already d
efined in common.obj
rubysound_system.obj : error LNK2005: _MemoryBarrier already defined in common.o
bj
rubysound_system.obj : error LNK2005: _RtlSecureZeroMemory already defined in co
mmon.obj
rubysound_vector.obj : error LNK2005: _InterlockedBitTestAndComplement already d
efined in common.obj
rubysound_vector.obj : error LNK2005: _MemoryBarrier already defined in common.o
bj
rubysound_vector.obj : error LNK2005: _RtlSecureZeroMemory already defined in co
mmon.obj

[/code]

The -l stdc++ option is needed for compilation on unix environments. Is there an alternative option for Windows that I may need

There are more linking errors, but I don't think the other ones are the problem.

Anyhow, as you can see, all of those symbols are already defined in the first compiled file (common.c) and any subsequent file that tries to link to them also has them defined. Does anyone have any idea what could be wrong

The functions that are supposidly already defined are not anywhere in my code, and researching them has turned up that they are a part of the WIN32 API.

Thanks in advance


Answer this question

Link errors : InterlockedBitTestAndComplement, MemoryBarrier, RtlSecureZeroMemory

  • JeroGrav

    That is exactly what I would have thought had common.c not been written by me and contain no defintions like that of any sort

    common.c:
    #include <fmod.h>
    #include <fmod_errors.h>
    #include <ruby.h>

    void ERRCHECK(FMOD_RESULT result, const char* file, int line )
    {
    if (result != FMOD_OK)
    {
    printf("FMOD error! (%d) %s %s %d\n", result, FMOD_ErrorString(result), file, line);
    rb_raise(rb_eRuntimeError, "FMOD error! (%d) %s", result, FMOD_ErrorString(result));
    //exit(-1);
    }
    }

    void sound_mark(FMOD_SOUND *sound){}

    void sound_free(FMOD_SOUND *sound){ FMOD_Sound_Release( sound ); }

    void system_mark(FMOD_SYSTEM *system){}
    void system_free(FMOD_SYSTEM *system){FMOD_System_Close( system ); FMOD_System_Release( system );}

    void channel_mark(FMOD_CHANNEL *channel){}
    void channel_free(FMOD_CHANNEL *channel){ free( channel );}

    void dsp_mark( FMOD_DSP* dsp ){}
    void dsp_free( FMOD_DSP* dsp ){ FMOD_DSP_Release(dsp);}

    void vector_mark(FMOD_DSP *vector){}
    void vector_free(FMOD_DSP *vector){ free( vector );}

    void geometry_mark(FMOD_DSP *geometry){}
    void geometry_free(FMOD_GEOMETRY *geometry){FMOD_Geometry_Release( geometry );}

    void channelGroup_mark(FMOD_DSP *channelGroup){}

    void channelGroup_free(FMOD_DSP *channelGroup){free( channelGroup );}

    inline
    VALUE bool2val( FMOD_BOOL val )
    {
    if ( val > 0 ) return Qtrue;
    return Qfalse;
    }

    I really doubt ruby.h is doing it... Other programs compile on VC8 using fmod.h and fmod_errors.h work fine, so I don't think it is that.

  • YoungJoe

    So after messing around, trying to compile any ruby extension that has multiple source files that reference fmod.h will fail.

    but fmod.h, and all files it includes, do not include any windows headers whatsoever.

  • Marlin7


    So it looks like those functions are somehow being defined from winnt.h

    Part of common.i:
    #line 2719 "C:\\Program Files\\Microsoft Platform SDK\\Include\\.\\winnt.h"


    #pragma warning(push)
    #pragma warning(disable:4035 4793)

    BOOLEAN

    InterlockedBitTestAndComplement (
    LONG *Base,
    LONG Bit
    )
    {
    __asm {
    mov eax, Bit
    mov ecx, Base
    lock btc [ecx], eax
    setc al
    };
    }

    Which I think are being included from one of the fmod headers, but I'm not sure how to tell.
    So.. I'm really at a loss to do right now, but I'll fiddle with it and try to come up with another way to proceed, unless anyone else can think of something.

  • rwilson06

    The Windows equivalent of the Unix stdc++ is probably one of the variants of the C++ runtimes - either msvcprtd.lib or libcpmt.lib.

    The rest of the error you are, as you have already realized, all Win32 functions - so it looks as if the application that you are compiling provides its own definition of these functions (in common.c) but it is also still linking against the Win32 libraries (probably kernel32.lib). This makes me suspect that the application may have been orginally developed on Win32 and these definitions were added to common.c to make it easier to port the application to Unix. Note: even though some of these functions by not be directly referenced in your code they are probably indirectly referenced by a lot other functions (some of them like _RtlSecureZeroMemory are pretty core to Win32).

    As it looks like you are porting the application back to Windows the easiest thing might be to just ignore the definition is common.c. You may find they are all under some sort of #ifdef ... #endif block and that if you set or clear a specific preprocessor definition then they will not be included in the build.



  • ruivlessa

    I would try compiling common.c with /P or /E and take at the preprocess output - if the linker is attributing these definitions to common.obj then they have to be defined somewhere in this compiland - either that or there is another common.obj somewhere in the project or in a library referenced by the project.

  • Thomas LEBRUN

    wow... After hours of working on this problem the issue seems to be in which order the headers are included.

    Including ruby.h before any fmod header fixed the problem.

    No idea why this is the case, but whatever.

  • Link errors : InterlockedBitTestAndComplement, MemoryBarrier, RtlSecureZeroMemory