首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何排除故障:未定义对` ...`的非虚拟thunk的引用

如何排除故障:未定义对` ...`的非虚拟thunk的引用
EN

Stack Overflow用户
提问于 2013-01-04 06:36:58
回答 1查看 10.3K关注 0票数 5

我正在试着找出如何进一步解决这个问题。我还想知道如何安装更新版本的ld,如果这样做有意义的话。所有相关的包管理器都告诉我,我是最新的。

该代码在ubuntu 12.04和12.10上使用g++ (4.7.2)进行编译、链接和运行,但在FC17上无法编译,并显示此错误。

代码语言:javascript
复制
ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58): undefined reference to `IHawk::EncryptedHandle::OnNewSecretKey(IHawk::IHPGP::SecretKey&)'
ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x8c): undefined reference to `non-virtual thunk to IHawk::EncryptedHandle::OnNewSecretKey(IHawk::IHPGP::SecretKey&)'

ld的版本:

代码语言:javascript
复制
12.04 only reports          2.22   (no indication other than 2.22)
12.10 reports               2.22.90.20120924
fedora17 reports            2.22.52.0.1-10.fc17 20120131

G++的版本:

代码语言:javascript
复制
Ubuntu 12.04    (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Ubuntu 12.10    (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
FC 17           (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

包含此方法的所有类的声明如下所示:

代码语言:javascript
复制
../Include/IHawkLib/IHPGP.h:            virtual bool OnNewSecretKey( SecretKey &skey ) = 0;
../Include/IHawkLib/PgpPkidParser.h:            virtual bool OnNewSecretKey( SecretKey &skey )                  {return true;}
../Include/IHawkLib/EncryptedFileHandle.h:              virtual bool OnNewSecretKey( SecretKey &skey );

但这就像g++忘记将虚拟部分传递给ld,因此它可以在link/ld时间解析它。这似乎发生在2002和2009年,可能还有其他几次,但在这种情况下,较新的版本似乎已经解决了问题。这一次,它看起来是特定于平台的,考虑到它不满意的代码,这是没有意义的。

生成错误的用法是:

代码语言:javascript
复制
    std::auto_ptr<IHawk::EncryptedFileHandle> apTmgHandle (GetFileHandle(filename, true, false, pKeyServer));
    if (apTmgHandle.get()){

类派生如下所示:

代码语言:javascript
复制
class EncryptedFileHandle : public EncryptedHandle {
....
    // Does not mention OnNewSecretKey
....
}

class EncryptedHandle : public IHawk::GenericHandle, protected IHawk::IHPGP {
....
    virtual bool OnNewSecretKey( SecretKey &skey );  // Has a concrete implementation
....
}

class IHPGP {
....
    virtual bool OnNewSecretKey( SecretKey &skey ) = 0;
....
}

class GenericHandle {
....
    // Has no clue about OnNewSecretKey
....
}

链接器命令在所有平台上看起来都是这样的,我们使用的是scons,到目前为止,它是平台无关的……(很抱歉排了这么长的队,只是不想冒着打字错误的风险:

代码语言:javascript
复制
g++ -o debug-posix/ArchiveService -g debug-posix/StdAfx.o debug-posix/ArchiveService_PosixMain.o debug-posix/WebCommands.o -L/usr/local/lib -L/usr/lib/mysql -L/home/mjones/C++/ifl/src/IHDB/debug-posix -L/home/mjones/C++/ifl/src/IHDB -L/home/mjones/C++/ifl/src/XMLib/debug-posix -L/home/mjones/C++/ifl/src/XMLib -L/home/mjones/C++/ifl/src/IHawkLib/debug-posix -L/home/mjones/C++/ifl/src/IHawkLib -L/home/mjones/C++/ifl/src/ImageCore/debug-posix -L/home/mjones/C++/ifl/src/ImageCore -L/home/mjones/C++/ifl/libraries/z39.50/ZExtensions/debug-posix -L/home/mjones/C++/ifl/libraries/z39.50/ZExtensions -L/home/mjones/C++/ifl/src/ServerGuts/debug-posix -L/home/mjones/C++/ifl/src/ServerGuts -L/home/mjones/C++/ifl/libraries/CRUSHER/debug-posix -L/home/mjones/C++/ifl/libraries/CRUSHER -L/home/mjones/C++/ifl/libraries/jsoncpp/debug-posix -L/home/mjones/C++/ifl/libraries/jsoncpp ArchiveServiceLib/debug-posix/libArchiveLib.a -lIHDB -lXMLib -lIHawk -lImageCore -lZExtensions -lServerGuts -lCrusher -ljson -lboost_filesystem-mt -lboost_thread-mt -lboost_regex-mt -lz -lMagickWand -lcrypto++ -lcppunit -llog4cplus -lyaz -lpodofo -lmysqlclient -lxerces-c -ljpeg -lpng -ltiff
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-04 06:52:51

解决问题的第一步是定位定义IHawk::EncryptedHandle的位置。这可以在对象文件上使用nm来完成,例如:

代码语言:javascript
复制
nm -po *.o | c++filt | grep IHawk::EncryptedHandle | grep -v ' U ' | less

如果定义来自库,则可以添加相应的库或在相应目录上使用*.a*.so。一旦找到符号并位于库中(由于未定义的引用来自库,因此丢失的符号也很可能位于库中),您需要确保在引用它的库之后指定包含丢失符号的库。自从我看到它发生已经有一段时间了,但是如果符号来自同一个库,你可能需要在库上运行ranlib

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14148380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档