Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Link to GDAL Library
Forum Updated to NodeBB v4.3 + New Features

Link to GDAL Library

Scheduled Pinned Locked Moved Solved 3rd Party Software
12 Posts 5 Posters 6.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TremblayGIS
    wrote on last edited by VRonin
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TremblayGIS
        wrote on last edited by
        #3

        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

        jsulmJ 1 Reply Last reply
        0
        • T TremblayGIS

          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

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          3
          • jsulmJ jsulm

            @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
            
            T Offline
            T Offline
            TremblayGIS
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              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.

              1 Reply Last reply
              1
              • T Offline
                T Offline
                TremblayGIS
                wrote on last edited by
                #7

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

                regards

                mrjjM 1 Reply Last reply
                0
                • T TremblayGIS

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

                  regards

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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 :)

                  1 Reply Last reply
                  3
                  • T Offline
                    T Offline
                    TremblayGIS
                    wrote on last edited by
                    #9

                    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

                    jsulmJ 1 Reply Last reply
                    0
                    • T TremblayGIS

                      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

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      3
                      • BuckwheatB Offline
                        BuckwheatB Offline
                        Buckwheat
                        wrote on last edited by
                        #11

                        @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.

                        Dave Fileccia

                        1 Reply Last reply
                        1
                        • T Offline
                          T Offline
                          TremblayGIS
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved