Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined reference errors for operator functions #488

Closed
kankaristo opened this issue Mar 11, 2016 · 2 comments · Fixed by #489
Closed

Undefined reference errors for operator functions #488

kankaristo opened this issue Mar 11, 2016 · 2 comments · Fixed by #489

Comments

@kankaristo
Copy link

I'm updating GLM from 0.9.5 to 0.9.7.3 and I'm getting a lot of undefined reference errors.

There seem to be duplicate declarations (the exact same function is declared twice, but only defined once), as well as some actual undefined references (i.e. there's a declaration, but no definition).

I'm using SWIG to generate Lua wrappers for GLM, so most template functions are actually instantiated, where they would regularly just not be compiled unless you use them (and you probably wouldn't get any of these errors).

SWIG can't handle all C++ templates, so I could be barking up the wrong tree for some these. Here's an example of some of the errors:

glm/detail/type_vec4.hpp has 5 declarations for operator*:

template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, T scalar);

template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, tvec1<T, P> const & scalar);

template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator*(T scalar, tvec4<T, P> const & v);

template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator*(tvec1<T, P> const & scalar, tvec4<T, P> const & v);

template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v1, tvec4<T, P> const & v2);

But glm/detail/type_vec4.inl only has 3 definitions:

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tvec4<T, P> const & v, T scalar)
{
    return tvec4<T, P>(
        v.x * scalar,
        v.y * scalar,
        v.z * scalar,
        v.w * scalar);
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> operator*(T scalar, tvec4<T, P> const & v)
{
    return tvec4<T, P>(
        scalar * v.x,
        scalar * v.y,
        scalar * v.z,
        scalar * v.w);
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tvec4<T, P> const & v1, tvec4<T, P> const & v2)
{
    return tvec4<T, P>(
        v1.x * v2.x,
        v1.y * v2.y,
        v1.z * v2.z,
        v1.w * v2.w);
}

And sure enough, I'm getting undefined reference errors for the 2 missing definitions:

obj/Release/HactEngine/swig_glm_wrap1.o: In function `_wrap___mul__SWIG_157':
/home/sami/IndiumGames/Infamis/engine/build/Release/swig_glm_wrap.cxx:125790: undefined reference to `glm::tvec4<float, (glm::precision)0> glm::operator*<float, (glm::precision)0>(glm::tvec4<float, (glm::precision)0> const&, glm::tvec1<float, (glm::precision)0> const&)'
obj/Release/HactEngine/swig_glm_wrap1.o: In function `_wrap___mul__SWIG_159':
/home/sami/IndiumGames/Infamis/engine/build/Release/swig_glm_wrap.cxx:125854: undefined reference to `glm::tvec4<float, (glm::precision)0> glm::operator*<float, (glm::precision)0>(glm::tvec1<float, (glm::precision)0> const&, glm::tvec4<float, (glm::precision)0> const&)'

I'm getting 6 of these errors from type_vec4.hpp alone. I'm working my way through the errors as the compiler (g++ 5.2.1) gives them, and I'll report back with a full list of the errors soon.

Should the declarations be removed, or are the definitions actually missing? If the declarations should be removed, I could make a PR. But if the definitions are missing, I'd rather just give you a list (I'd be in over my head trying to write the definitions).

@kankaristo
Copy link
Author

I've found and fixed 10 of these errors.

The ones I've listed above seem to have missing definitions (other vector types have similar functions defined), some of the errors are because of duplicate declarations (2 declarations for the same function) and there's even one "typo", where the declaration is different from the definition.

I'm currently using GLM 0.9.7.3, but looking at the source code, I don't think these are fixed in master either. I'll fork and open a PR, hopefully during this weekend.

@kankaristo
Copy link
Author

Created a PR here: #489

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant