Assimp model loading library install/linking troub

2020-08-15 02:49发布

问题:

I'm trying to install Assimp to use in my projects, but I'm having some trouble. I'm currently using win 10 pro and visual studio 15 2017.

  1. I have downloaded Assimp 4.0.1.zip, extracted it into a directory, loaded cmakeGui and ran configuration twice, then generated into Assimp/build directory.

  2. Next I went into Assimp/build and I ran the Assimp.sln and chose the ALL_BUILD I think it was. I then copied all the files in the /code/debug that were alongside the .lib and .dll and moved them all into the Debug directory of my project where my exe is built to. I copied the .lib into my opengl/libs directory and all the headers in /include from the originally extracted download into my opengl/includes/assimp directory.

  3. Finally, I adjusted my projects linker settings to include the assimp.lib and assimp.dll (alias for simplicity of this post)

When I tried to build the project it said it could not open the dll and when experimenting I copied the dll into the project dir alongside main.cpp and my other files and ran again, it this time said "invalid or corrupt file: cannot read at 0x378"


It's safe to say I need to study up on compiling, linking and cmake but for now I started over.

I thought I had it working(and maybe I do...) after I got it to stop complaining when I was including the headers into my project. To do so I started from fresh, built Assimp same as before, moved all the files with the dll into my libs directory, dumped all the includes from the download into my includes, also move the config.h from the build into this directory. Then I set the linker settings in the project and didn't move anything into my project directories.

After that, it stopped complaining so I proceeded with the tutorial series I was following. I compiled, got a load of errors, fixed them down to 0 then suddenly I got 8 new ones in their place.

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol _aiGetMaterialTextureCount referenced in function "public: unsigned int __thiscall aiMaterial::GetTextureCount(enum aiTextureType)const " (?GetTextureCount@aiMaterial@@QBEIW4aiTextureType@@@Z) opengl_model_loading F:\Desktop\MyDocuments\Tuts\opengl\getting started\opengl_model_loading\opengl_model_loading\main.obj 1

This error gave me the feeling it was probably due to the dll. Please advise.

回答1:

I've just recently done this myself & will say had lot of trouble with v401 & getting errors or linking issues. Successfully got mine working with following;

Note: ASSIMP does have boost as a dependency.

  1. Download/clone master Asset-Importer-Lib from github: https://github.com/assimp/assimp
  2. Open Cmake GUI & once open:

    • Where is the Source code: "..\MyDocuments\assimp\assimp-master"
    • Where to build the binaries: "..\MyDocuments\assimp\assimp-master\build". You will need to make a build folder & point Cmake to it.

    2.1. Alternatively if you're familiar with command line option: generate project files with relevant paths using

    • cmake -G”Visual Studio 14 Win64"
  3. Click configure.
  4. Then Generate. Make sure you select correct build option ie VS15 2017 64bit.
  5. Load "..\MyDocuments\assimp\assimp-master\build\Assimp.sln" with Visual studio.
  6. Right click "ALL_BUILD" & select "Build". This will take several minutes. Once done & no errors, it should create necessary *.dll/*.lib in ..\MyDocuments\assimp\assimp-master\build\code\Debug
  7. Link & include into your existing project the relevant *.lib & also "..\MyDocuments\assimp\assimp-master\include\assimp" folder. You will also need to make sure *.dll file is in the same folder, or included, as the *exe you're running.
  8. You may also need to copy over from the ..\MyDocuments\assimp\assimp-master\build\include\assimp\config.h" & include it in step7.

Just ensure you're building right libraries for your code ie 32/64bit/debug/release/unicode/etc, otherwise may encounter issues still.

Following video is useful for the visually inclined. https://youtu.be/W_Ey_YPUjMk

Hope this helps.

EDIT: If you want static library version ie no .dll required: From above steps:

5.1. Change relevant project configuration type & extension from .dll to .lib type (should be two: assimp & zlib).

5.2. Right click "UpdateAssimpLibsDebugSymbolsAndDLLs" ->Properties->Build Events & update the paths in the command line sections from ..\Path*.dll to ..\Path*.lib. (If encounter errors, do same on assimp_cmd project).

  1. Same as above but now also need to link your project to IrrXML.lib & zlibd.lib. Should no longer need the *.dll file.