I am in the middle of porting data from a Visual Studio project to Mingw GCC.
I believe I have run into a library linking order issue and am not really sure on how to circumvent this issue. I currently have two files CWavImaData.cpp
and CWavData.cpp
. Now both these files contain the following statement
{
WAVEFORMATEXTENSIBLE *pex = reinterpret_cast<WAVEFORMATEXTENSIBLE*>(new char[sizeof(WAVEFORMATEXTENSIBLE)]);
....
....
pex->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; <-- Conflicting Statement
}
Now KSDATAFORMAT_SUBTYPE_PCM
depeds on the library libksguid.a
. Now if I comment out the conflicting statement in CWavData.cpp
the project builds fine.
However if I un-comment this conflicting statement I get the linker error.
CWavData.cpp:156: undefined reference to `_GUID const& __mingw_uuidof<KSDATAFORMAT_SUBTYPE_PCM_STRUCT>()'
This makes me think that there is a linker error. Here is my build output
g++.exe -shared -Wl,--output-def=libsndlib.def -Wl,--out-implib=libsndlib.a -Wl,--dll -LC:\mingw64\x86_64-w64-mingw32\lib -Lc:\MyProj\SharedFunctions\ -L"Win32\Debug x64" "Win32\Debug x64\ADPCM\CWavImaData.o" "Win32\Debug x64\CCategoryLst.o" "Win32\Debug x64\CSampleList.o" "Win32\Debug x64\CSeqScptList.o" "Win32\Debug x64\CSndDrv.o" "Win32\Debug x64\CSndLib.o" "Win32\Debug x64\CSndRam.o" "Win32\Debug x64\CSndScptList.o" "Win32\Debug x64\CSndSeq.o" "Win32\Debug x64\CSndStrHdl.o" "Win32\Debug x64\CWavData.o" "Win32\Debug x64\CWavDataList.o" "Win32\Debug x64\CWavDataStr.o" "Win32\Debug x64\dllmain.o" "Win32\Debug x64\misc\assert\myassert.o" "Win32\Debug x64\misc\CFindFile.o" "Win32\Debug x64\misc\CStrings.o" "Win32\Debug x64\misc\mydxerr.o" "Win32\Debug x64\SndInt.o" -o sndlib.dll -lksguid -lSharedFunctions -lole32 -lwinmm -ldsound -lksguid -lksguid
Win32\Debug x64\CWavData.o: In function `CWavData::AnalyzeFormatChunk(_iobuf*, long)':
C:/MyProj/sndlib/CWavData.cpp:156: undefined reference to `_GUID const& __mingw_uuidof<KSDATAFORMAT_SUBTYPE_PCM_STRUCT>()'
collect2.exe: error: ld returned 1 exit status
I even tried adding ksguid
twice however I am still getting a linker error. The file CWavImaData.cpp
builds fine alone with this statement however when this statement is included with the file CWavData.cpp
I get a linker error. Any suggestions on how I can resolve this issue ?
Update: I have been suggested to use --start-group. After trying it this is what my output looks like
g++.exe -shared -Wl,--output-def=libsndlib.def -Wl,--out-implib=libsndlib.a -Wl,--dll -LC:\mingw64\x86_64-w64-mingw32\lib -Lc:\MyProj\SharedFunctions\SharedFunctions\ -L"Win32\Debug x64" "Win32\Debug x64\ADPCM\CWavImaData.o" "Win32\Debug x64\CCategoryLst.o" "Win32\Debug x64\CSampleList.o" "Win32\Debug x64\CSeqScptList.o" "Win32\Debug x64\CSndDrv.o" "Win32\Debug x64\CSndLib.o" "Win32\Debug x64\CSndRam.o" "Win32\Debug x64\CSndScptList.o" "Win32\Debug x64\CSndSeq.o" "Win32\Debug x64\CSndStrHdl.o" "Win32\Debug x64\CWavData.o" "Win32\Debug x64\CWavDataList.o" "Win32\Debug x64\CWavDataStr.o" "Win32\Debug x64\dllmain.o" "Win32\Debug x64\misc\assert\myassert.o" "Win32\Debug x64\misc\CFindFile.o" "Win32\Debug x64\misc\CStrings.o" "Win32\Debug x64\misc\mydxerr.o" "Win32\Debug x64\SndInt.o" -o sndlib.dll -Wl,--start-group -lksguid -Wl,--end-group -lksguid -lSharedFunctions -lole32 -lwinmm -ldsound -lksguid -ldxerr8 -ldxerr9
Win32\Debug x64\CWavData.o: In function `CWavData::AnalyzeFormatChunk(_iobuf*, long)':
c:/MyProj/sndlib/CWavData.cpp:156: undefined reference to `_GUID const& __mingw_uuidof<KSDATAFORMAT_SUBTYPE_PCM_STRUCT>()'
I then tried this too
.. -o sndlib.dll -Wl,--start-group -lksguid -lSharedFunctions -lole32 -lwinmm -ldsound -Wl,--end-group
I also tried this
.. -Wl,--start-group -lksguid -Wl,--end-group -lSharedFunctions -lole32 -lwinmm -ldsound
I am still getting the linker error. Any suggestions ?