简体   繁体   中英

Dynamic math library - unresolved externals

At first I would like to point out that I'm new to linking, libraries and stuff.

I'm trying to implement simple math library (dynamic) for vectors and matrices. I'm using Visual Studio. Let's say I have 2 projects, one si DLL and other is console app to test it.

I've declared preprocessor macro for export:

#define GE_API __declspec(dllexport)

This is my matrix class:

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>();

Problem is that when I try to compile I get unresolved eternal symbols error. I guess that its because class float4x4 gets exported but function make_identity does not. But if thats right how can I export function make_identity() ?

You have to define GE_API differently. In the project where you build the DLL, you have to use:

#define GE_API __declspec(dllexport)

in the project where you use the DLL, you have to use:

#define GE_API __declspec(dllimport)

You can streamline that by using something like:

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

and make sure that you define the pre-processor macro _BUILD_GE_API_DLL in the project used to build the DLL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM