【问题标题】:visual studio 2012 can't resolve static fields in a dll libVisual Studio 2012 无法解析 dll 库中的静态字段
【发布时间】:2013-04-27 16:41:20
【问题描述】:

我正在使用 Visual Studio 2012 x64 dll 编译 openexr2.0.0,我收到此错误:

ImfLut.obj : error LNK2001: unresolved external symbol "private: static union half::uif const * const half::_toFloat" (?_toFloat@half@@0QBTuif@1@B)

ImfRgbaYca.obj : error LNK2001: unresolved external symbol "private: static unsigned short const * const half::_eLut" (?_eLut@half@@0QBGB)

我使用 dumpbin /exports 在 half.lib 中查找:

在 half.dll 上使用 dumpbin /exports 进行另一个查找:

这两个符号在那里。有趣的是,当我从依赖项中删除 half.lib 时,VS 抱怨 convert 也没有解决。这表明它可以找到convert 而不是_toFloat 和_eLut。区别在于:_toFloat 和 _eLut 都是静态字段,convert 是静态方法。

    class half
    {
        ...
      public:

        union uif
        {
        unsigned int    i;
        float       f;
        };

      private:

        HALF_EXPORT static short                  convert (int i);

        HALF_EXPORT static const uif              _toFloat[1 << 16];
        HALF_EXPORT static const unsigned short   _eLut[1 << 9];
        ...
    };

我的系统是 windows 8 x64。有谁知道如何解决这个问题?

【问题讨论】:

  • 似乎convert方法是在编译成half.dll的.cpp文件中实现的,而变量_toFloat_eLut不是。
  • 我更新了问题,在 half.dll 上使用了 dumpbin。符号在那里。我正在编译 ilmimf.dll。我认为编译库不需要 half.dll。
  • @Shen 这与我现在面临的错误完全相同。我正在尝试编译alembic 1.5.8,你最后是怎么解决的?

标签: dll visual-studio-2012 openexr


【解决方案1】:

您正在尝试链接 __declspec(dllexport)-ed 符号。 这意味着您需要确保您在项目文件中使用__declspec(dllimport)-ing 那些符号。 专门针对 half - 您可以添加一个 #defineOPENEXR_DLL 正在检查 halfExport.h 中的外观,并将为您执行此操作。

【讨论】:

    【解决方案2】:

    以下链接中的第 14 步为我解决了这个问题:

    https://groups.google.com/forum/#!topic/openvdb-forum/-jFJQ2N4BGc

    在您的项目中,将OPENEXR_DLL添加到“项目属性->C/C++->预处理器”中的“预处理器定义”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多