动态数学库 - 未解析的外部函数

Dynamic math library - unresolved externals

提问人:mezo 提问时间:2/18/2015 更新时间:2/18/2015 访问量:93

问:

首先,我想指出的是,我是链接、库和其他东西的新手。

我正在尝试为向量和矩阵实现简单的数学库(动态)。我正在使用 Visual Studio。假设我有 2 个项目,一个是 si DLL,另一个是控制台应用程序来测试它。

我已经声明了用于导出的预处理器宏:

#define GE_API __declspec(dllexport)

这是我的矩阵类:

class GE_API float4x4
{
public:
    // The four columns of the matrix
    float4 c1;
    float4 c2;
    float4 c3;
    float4 c4;

    /**
    */
    float4& operator [] (const size_t i);
    const float4& operator [] (const size_t i) const;

    /**
    * Index into matrix, valid ranges are [1,4], [1,4]
    */
    const float &operator()(const size_t row, const size_t column) const { return *(&(&c1 + column - 1)->x + row - 1); }
    float &operator()(const size_t row, const size_t column) { return *(&(&c1 + column - 1)->x + row - 1); }

    /**
    */
    bool operator == (const float4x4& m) const;
    /**
    */
    bool operator != (const float4x4& m) const;
    /**
    */
    const float4 row(int i) const;
    /**
    * Component wise addition.
    */
    const float4x4 operator + (const float4x4& m);
    /**
    * Component wise scale.
    */
    const float4x4 operator * (const float& s) const;
    /**
    * Multiplication by column vector.
    */
    const float4 operator * (const float4& v) const;
    /**
    */
    const float4x4 operator * (const float4x4& m) const;
    /**
    */
    //const float3 &getTranslation() const { return *reinterpret_cast<const float3 *>(&c4); }
    const float3 getTranslation() const
    {
        return make_vector(c4.x, c4.y, c4.z);
    }
};


/**
*/
template <>
const float4x4 make_identity<float4x4>();

问题是,当我尝试编译时,我得到未解决的永恒符号错误。我想这是因为类被导出,但函数make_identity没有。但是,如果这是正确的,我该如何导出函数?float4x4make_identity()

C++ DLL visual-studio-2013 未解析的外部

评论


答:

0赞 R Sahu 2/18/2015 #1

你必须以不同的方式定义。在生成 DLL 的项目中,必须使用:GE_API

#define GE_API __declspec(dllexport)

在使用 DLL 的项目中,必须使用:

#define GE_API __declspec(dllimport)

您可以使用以下方法简化它:

#ifdef _BUILD_GE_API_DLL
#define GE_API __declspec(dllexport)
#else
#define GE_API __declspec(dllimport)
#endif

并确保在用于生成 DLL 的项目中定义预处理器宏。_BUILD_GE_API_DLL