Link to GDAL Library



  • Hello
    i'm currently trying to use a GDL Library in qtcreator.
    right now i 'm just trying to open a gdal file in the main.cpp.
    I have edited the *.pro file like this :

    QT += core
    QT -= gui
    CONFIG += c++11
    TARGET = ATS_test
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    LIBS += -L$$PWD/gdal212/lib/
    INCLUDEPATH += $$PWD/gdal212/include
    

    then here is the main.cpp :

    #include <QCoreApplication>
    #include "gdal.h"
    #include "gdal_priv.h"
    #include "cpl_conv.h" // for CPLMalloc()
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        const char * pszFilename ;
        GDALDataset  *poDataset;
        GDALAllRegister();
        return a.exec();
    }
    

    during the compilation i get this message :
    D:\Documents\qt\ATS_test\main.cpp:13: erreur : undefined reference to `GDALAllRegister@0'

    i do not understand because when i'm typing GDALAl..... the selfcompletion work well and i can get the GDALAllRegister(); function.

    could you please help me ?

    Regards


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are not linking to the library itself.

    i.e. you are missing something like LIBS += -lgdal in your .pro file.



  • Hello
    Thank you so much for this
    i understand now : i need to set the name of the lib.

    i have tried this :
    LIBS += -L$$PWD/gdal212/lib/ -lgdal

    i get this : : -1: erreur : cannot find -lgdal

    i checked the lib repertory. There is no lgdal.lib file. there is a gdal_i.lib fil

    So i tried this : LIBS += -L$$PWD/gdal212/lib/ -gdal_i
    i get this : D:\Documents\qt\ATS_test\main.cpp:13: erreur : undefined reference to `GDALAllRegister@0'

    I am not a very advanced user, so i'm doing something wrong, but what ?

    Thanks in advance for your help


  • Moderators

    @TremblayGIS -l is the parameter telling the linker to link against the lib which is following the parameter - you need to keep it!
    It should be:

    LIBS += -L$$PWD/gdal212/lib/ -lgdal_i
    


  • Hello

    So i tried this : LIBS += -L$$PWD/gdal212/lib/ -lgdal_i
    i still get this : D:\Documents\qt\ATS_test\main.cpp:13: erreur : undefined reference to `GDALAllRegister@0'

    i guess i have an issue about my connexion with the lib.
    How can i check if something else is wrong ?
    regards


  • Qt Champions 2016

    Hi
    Is the GDL Library compiled with same version of the compiler you use for the test project?
    Meaning both are mingw or both are visual studio compiler?

    If you have downloaded the LIB file precompiled, it might not be compatible with the compiler you use.



  • Hello
    indeed in use *.lib files.
    Do you suggess me to compile by myself the .cpp files ?

    regards


  • Qt Champions 2016

    @TremblayGIS
    Hi, on windows you cannot mix libs/dlls from visual studio and mingw compiler.
    Or reverse. You can also have issued using same compiler , but differnt version.
    Like VS2015 and vs2013.
    So yes, if you are using mingw compiler and libs are premade with visual studio then
    the only road forward is compile it yourself.

    So check the docs for the GDAL and see what you really have downloaded :)



  • Hi
    you are right the .lib where compiled with VS so i need to do it my self.

    One i got the .cpp and .h files, could i compile them with qt ? What kind of compiler does qt use ?
    Sorry in advance if my question is stupid :(

    regards


  • Moderators

    @TremblayGIS You don't compile it with Qt - Qt is not a compiler. You compile it with the same compiler you use for Qt - MinGW in your case, right? MinGW is usually located in c:\Qt\Tools\mingw...\bin



  • @TremblayGIS
    I use GDAL pretty extensively on both Linux and Windows using MSYS2 toolkit. Building GDAL is super easy on MSYS2 and Linux (although Linux may have a distro) using the configuration tools.

    For both it is:
    ./autogen.sh
    ./configure
    make

    You can download binaries, usually, for V$.

    You should copy the gdal*.dll to your build folder as GDAL mostly installs a shared library.

    As a side note, you should also build the PROJ.4 library as GDAL uses it for its geospatial referencing.



  • Hello
    sorry for the delay
    your suggestions solved my problem :
    the lib i got were built with VS... after buidling with MinGW it works
    thank you for your help
    regards


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.