2015-02-17 39 views
0

首先我想指出,我是链接,库和东西的新手。动态数学库 - 无法解析的外部结构

我正试图为矢量和矩阵实现简单的数学库(动态)。我正在使用Visual Studio。假设我有两个项目,一个是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()

回答

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 

,并确保您定义的预处理器宏_BUILD_GE_API_DLL用于构建该DLL的项目。