I have bee trying to get assimp running in QT 5.2 in order to import some 3D objects, but Im having a problem with (I believe) the linker.
I installed it via cmake, first downloading the source files from here http://sourceforge.net/projects/assimp/files/assimp-3.0/, then using cmake to compile and install.
Then, I have tried to run the example they provide in the documentation
#include <assimp/cimport.h> // Plain-C interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
bool DoTheImportThing( const char* pFile)
{
// Start the import on the given file with some example postprocessing
// Usually - if speed is not the most important aspect for you - you'll t
// probably to request more postprocessing than we do in this example.
const aiScene* scene = aiImportFile( pFile,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
// If the import failed, report it
if( !scene)
{
// DoTheErrorLogging( aiGetErrorString());
return false;
}
return true;
}
But when trying to compile this piece of code, I get the error
error: undefined reference to `aiImportFile'
error: collect2: error: ld returned 1 exit status
I am using a 32 bit linux mint. Does anybody have any idea why is it not linking? Should I have compiled with cmake using a specific flag? i havent been able to found any special flags in any posts around.
Thanks!
I finally solved it! Apparently, QT has a tool for importing external libraries. I just had to right click on the project, click add library, and add the file located at /user/local/libassimp.a
This added the following lines to my .pro file:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/release/ -lassimp
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/debug/ -lassimp
else:unix: LIBS += -L$$PWD/../../../../../usr/local/lib/ -lassimp
INCLUDEPATH += $$PWD/../../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../../usr/local/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/release/libassimp.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/debug/libassimp.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/release/assimp.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/debug/assimp.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/libassimp.a
Theres possibly a more elegant way of coding that, but at least it worked.