5

我试图弄清楚如何进一步解决这个问题。如果有意义的话,我还想知道如何安装更新版本的 ld 。所有涉及的包管理器都告诉我,我是最新的。

该代码在 ubuntu 12.04 和 12.10 上使用 g++ (4.7.2) 编译、链接和运行,但在 FC17 上编译失败并出现此错误。

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 的版本:

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++ 的版本:

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)

包含此方法的所有类的声明都说:

../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 以便它可以在链接/ld 时间解决它。这似乎发生在 2002 年和 2009 年,也许还有其他几次,但在这种情况下,较新的版本似乎已经解决了这个问题。这一次,它似乎是特定于平台的,考虑到它不满意的代码,这毫无意义。

构建错误来自的用法是:

    std::auto_ptr<IHawk::EncryptedFileHandle> apTmgHandle (GetFileHandle(filename, true, false, pKeyServer));
    if (apTmgHandle.get()){

类派生看起来像:

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 并且到目前为止已经能够与平台无关....(对不起,长线,只是不想冒险把它弄乱一个错字:

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
4

1 回答 1

6

解决问题的第一步是找到IHawk::EncryptedHandle定义的位置。这可以nm在目标文件上使用,例如:

nm -po *.o | c++filt | grep IHawk::EncryptedHandle | grep -v ' U ' | less

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

于 2013-01-03T22:52:50.833 回答