g-truc / glm

OpenGL Mathematics (GLM)
https://glm.g-truc.net
Other
9.05k stars 2.1k forks source link

'quat_cast': identifier not found when using glm as C++20 module #1298

Open Silverlan opened 3 months ago

Silverlan commented 3 months ago

The issue happens if you try to use the glm::mat4 constructor of glm::quat, when using glm as a module under Visual Studio 2022. I've tried it with the latest GLM version (45008b2).

Code:

import glm;

int main(int argc, char* argv[]) {
    glm::mat4 m;
    glm::quat q{ m };
    return 0;
}

I've set up a test repository for replicating the problem: https://github.com/Silverlan/test_glm_module Simply clone the repository (with submodules) and run the build.bat, or fork the repository and check the workflow output.

The line glm::quat q{ m }; causes this error:

D:\a\test_glm_module\test_glm_module\glm_cxxmodule\glm\glm\detail\type_quat.inl(240,11): error C3861: 'quat_cast': identifier not found [D:\a\test_glm_module\test_glm_module\build\glm_test.vcxproj]
  (compiling source file '../main.cpp')
  D:\a\test_glm_module\test_glm_module\glm_cxxmodule\glm\glm\detail\type_quat.inl(240,11):
  'quat_cast': function was not declared in the template definition context and can be found only via argument-dependent lookup in the instantiation context
  D:\a\test_glm_module\test_glm_module\glm_cxxmodule\glm\glm\detail\type_quat.inl(240,11):
  the template instantiation context (the oldest one first) is
    D:\a\test_glm_module\test_glm_module\main.cpp(5,12):
    see reference to class template instantiation 'glm::qua<float,glm::packed_highp>' being compiled
    D:\a\test_glm_module\test_glm_module\glm_cxxmodule\glm\glm\detail\type_quat.inl(239,2):
    while compiling class template member function 'glm::qua<float,glm::packed_highp>::qua(const glm::mat<4,4,glm::f32,glm::packed_highp> &)'
        D:\a\test_glm_module\test_glm_module\main.cpp(5,13):
        see the first reference to 'glm::qua<float,glm::packed_highp>::qua' in 'main'

If you call glm::gtc::quat_cast directly instead of using the constructor, the error vanishes:

import glm;

int main(int argc, char* argv[]) {
    glm::mat4 m;
    glm::quat q = glm::gtc::quat_cast(m);
    return 0;
}