有关库的链接顺序的问题 [英] Issue with Linking order of the libraries

查看:74
本文介绍了有关库的链接顺序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从Visual Studio项目移植到Mingw GCC. 我相信我遇到了一个图书馆链接订单问题,并且不确定如何规避此问题.我目前有两个文件CWavImaData.cppCWavData.cpp.现在,这两个文件都包含以下语句

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
}

现在,KSDATAFORMAT_SUBTYPE_PCM在库libksguid.a上使用.现在,如果我注释掉CWavData.cpp中的冲突语句,则项目可以正常运行. 但是,如果我取消注释此冲突的语句,则会出现链接器错误.

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

我什至尝试添加两次ksguid,但是仍然出现链接器错误.文件CWavImaData.cpp单独与此语句一起可以很好地构建,但是当该语句包含在文件CWavData.cpp中时,出现链接器错误.关于如何解决此问题的任何建议吗?

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 ?

更新: 建议我使用--start-group.尝试之后,这就是我的输出结果

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>()'

然后我也尝试了

.. -o sndlib.dll -Wl,--start-group -lksguid -lSharedFunctions -lole32 -lwinmm -ldsound  -Wl,--end-group 

我也尝试过

.. -Wl,--start-group -lksguid -Wl,--end-group -lSharedFunctions -lole32 -lwinmm -ldsound 

我仍然收到链接器错误.有什么建议吗?

I am still getting the linker error. Any suggestions ?

推荐答案

"这使我认为存在链接器错误."

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

当然这是

Of course that's a linker error, the ld appearing proves this. Order of object files and libraries matters, as they need to appear before used from another object file or library.

要使链接程序看到符号,需要克服特定顺序的方法是使用 -Wl,--end-group 用于GCC的选项,您可以用来创建其中出现的库组,而无需特定的顺序.

The way to overcome a specific order is needed to let the linker see the symbols, is to use the -Wl,--start-group and -Wl,--end-group options for GCC, you can use to create groups of libraries appearing within, without need for a particular order.

关于您的评论和更新,您应该尝试以下链接器命令行:

As for your comments and updates, you should try the following linker command line:

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"      
    -Wl,--start-group 
    -lksguid  -lSharedFunctions -lole32 -lwinmm -ldsound  
    -ldxerr8 -ldxerr9 
    -Wl,--end-group 
    -o sndlib.dll

这篇关于有关库的链接顺序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆