Search code examples
c++linkermingw-w64assimp

Assimp linking error with mingw-w64 (WinBuilds)


I'm trying to compile project that uses assimp with mingw-w64 (x86_64-w64-mingw32-g++), and linker produces this errors:

render/model.o: In function `Model::loadModel(std::string)':
render/model.cpp:9: undefined reference to `Assimp::Importer::Importer()'
render/model.cpp:15: undefined reference to `Assimp::Importer::GetErrorString() const'
render/model.cpp:20: undefined reference to `Assimp::Importer::~Importer()'
render/model.cpp:20: undefined reference to `Assimp::Importer::~Importer()'
render/model.o: In function `Assimp::Importer::ReadFile(std::string const&, unsigned int)':
include/assimp/Importer.hpp:653: undefined reference to `Assimp::Importer::ReadFile(char const*, unsigned int)'

That looks like linker cannot link assimp's dynamic library with project. I use .dll and .lib files, compiled from latest assimp source (with CMake and Visual Studio), and functions that linker can't find, are presented in dll and lib (checked with dumpbin). All files are x64 bit.

This is how I compile it:

x86_64-w64-mingw32-g++ -o main main.o <... other object files ...> -std=c++11 -Werror -Isrc -Iinclude -g -m64 -L ./lib -lgdi32 -lglu32 -lglew32 -lzlib1 -lopengl32 -lglfw3 -lirrKlang -lassimp

Already tried to use older precompiled binaries, it produces same results. Tried to compile assimp using mingw-w64, but failed.

Any ideas what causes linker not to see functions?


Solution

  • I replaced WinBuild (g++ 4.8.0) with MSYS2 (g++ 10.2.0), and recompiled assimp with mingw. Now everything from project compiles fine.