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

时间:2015-02-17 23:08:18

标签: c++ dll visual-studio-2013 unresolved-external

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

我正在尝试为矢量和矩阵实现简单的数学库(动态)。我正在使用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>();

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

1 个答案:

答案 0 :(得分:0)

您必须以不同方式定义GE_API。在构建DLL的项目中,您必须使用:

#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