Search code examples
c++visual-studioassimpname-mangling

Name mangling differences on same compiler, same settings


I'm trying to link ASSIMP into my project, on Windows 10 Visual Studio Community 2019 RC. I've built ASSIMP with CMake and the same version of VS. I've linked the lib file so that is all working.

mesh.obj : error LNK2019: unresolved external symbol
"public: class aiScene const * __cdecl Assimp::Importer::ReadFile(char const *,unsigned int)"
(?ReadFile@Importer@Assimp@@QEAAPEBVaiScene@@PEBDI@Z)
referenced in function
"public: static void __cdecl citrus::graphics::mesh::convertAnimationFromCollada(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"
(?convertAnimationFromCollada@mesh@graphics@citrus@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)

The key part is:

?ReadFile@Importer@Assimp@@QEAAPEBVaiScene@@PEBDI@Z

When I view the symbols in my generated assimp lib file I see:

?ReadFile@Importer@Assimp@@QEAAPEBUaiScene@@PEBDI@Z

So as you can see the name is slightly different, with the difference being QEAAPEBV changed to QEAAPEBU. What could cause this?


Solution

  • Using the undname command like tool, we find the two names are the mangled forms of

    public: class aiScene const * __ptr64 __cdecl Assimp::Importer::ReadFile(char const * __ptr64,unsigned int) __ptr64
    

    and

    public: struct aiScene const * __ptr64 __cdecl Assimp::Importer::ReadFile(char const * __ptr64,unsigned int) __ptr64
    

    for the V and U versions. So you can see that the difference is one is declared as a class aiScene, the other a struct aiScene.

    Somewhere in your code you are inconsistently declaring what aiScene is.