Results 1 to 7 of 7

Thread: Add a DLL to Qt Creator's run environment

  1. #1
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Add a DLL to Qt Creator's run environment

    This is a pretty simple question that I imagine has a very simple answer.

    I built a GDAL library on my workstation to work with shapefiles in my Qt app. After a day of troubleshooting and learning, I've sorted out building and compiling via customizing my .pro file.

    However, when I attempt to run the program from Qt Creator, it crashes immediately because it is missing a gdal-specific DLL (gdal19.dll). This is relatively easily fixed by copying gdal19.dll into my build target, but I'd rather not have to do this every time I rebuild or start a project. How would I tweak Qt Creator's Build & Run environment to link to a custom DLL at a fixed location on another drive?

    Qt Creator already links to the Qt DLLs stored elsewhere, so I imagine that this must is a simple setting somewhere that I simply don't know.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Add a DLL to Qt Creator's run environment

    Select Projects, Run Settings, expand the Run Environment, and modify the PATH variable to include the GDAL binary folder
    or
    Arrange for the same change to be made to the system/user PATH variable in Windows

  3. The following user says thank you to ChrisW67 for this useful post:

    Phlucious (27th June 2012)

  4. #3
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add a DLL to Qt Creator's run environment

    Thank you, that is what I was looking for. I thought that perhaps Qt Creator would have a config (*.cfg, *.inf, *.xml, etc) file where I could set library paths for the program, not just a particular project.

    It didn't occur to me to modify PATH. I opted for the Build & Run Environment option instead of modifying the system environment because I want my workstation to have the same system environment as my users. Reduces the odds that I'll forget a file when deploying.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Add a DLL to Qt Creator's run environment

    You can set the Windows PATH for a single user and base it on the system PATH. Just Add a user variable called PATH and set it to "c\some\other\path;d:\and \another" and this will be appended to the system's environment for that user.

  6. #5
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add a DLL to Qt Creator's run environment

    hi...I am pretty new to GDAL library. Can you help me understand how do i build GDAL lib with Qt.

  7. #6
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add a DLL to Qt Creator's run environment

    Sorry for necromancing hte thread, but I am as well trying to link with gdal and there's no way to do it.

    I've downloaded the precompiled version from here:
    https://trac.osgeo.org/gdal/wiki/BuildingOnWindows

    Both DEV and EXE and placed them on the same directory, having now: bin data include and lib.

    I've added lib and bin to the PATH and also to LIBS += -L{paths} -lgdal_i and the INCLUDEDIR.

    The headers are seen fine, but it can't find the symbols. Here's the error:

    Qt Code:
    1. moc_gpspublisher.obj:-1: error: LNK2001: unresolved external symbol "public: virtual __cdecl GDALMajorObject::~GDALMajorObject(void)" (??1GDALMajorObject@@UEAA@XZ)
    To copy to clipboard, switch view to plain text mode 

    I've tried using mingw, but I get the same unresolved symbol (althought at a different place). I've also done a dumpbin of the symbols of the dll:

    [...]
    Qt Code:
    1. 159 9E 00005F4C ??1GDALMajorObject@@UAE@XZ
    To copy to clipboard, switch view to plain text mode 
    [...]

    which demangled is:
    Qt Code:
    1. public: virtual __thiscall GDALMajorObject::~GDALMajorObject(void)
    To copy to clipboard, switch view to plain text mode 

    SO I noticed the difference __thiscall and __cdecl. The rellevant part of the code that defines what goes before each function is:
    Qt Code:
    1. #ifndef CPL_DLL
    2. #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
    3. # define CPL_DLL __declspec(dllexport)
    4. #else
    5. # define CPL_DLL
    6. #endif
    7. #endif
    To copy to clipboard, switch view to plain text mode 
    It's the first option that gets selected. I've tried selecting the second option and also defining it to __thiscall. When I do the first, I actually get the same two errors as in mingw, obviously since in mingw MSC_VER won't be defined. The errors say that the constructor and destructor of the only GDAL object ( OGRSpatialReference oSRS; ) I am declaring are not defined.
    Qt Code:
    1. main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl OGRSpatialReference::OGRSpatialReference(char const *)" (??0OGRSpatialReference@@QEAA@PEBD@Z) referenced in function "public: static void __cdecl GPSReader::project(void)" (?project@GPSReader@@SAXXZ)
    To copy to clipboard, switch view to plain text mode 

    With the second option (forcing __thiscall) I get many more errors, mainly that the left-side modifier cannot modigy pointers to data.

    So at this point I wanted to build GDAL from source, but it isn't straightforward. At least on windows.

    Am I missing something? How did you get it to work? Is it possible to find a gdal.lib somewhere??

    Cheers!

  8. #7
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add a DLL to Qt Creator's run environment

    So I finally managed to find the error and fix it. I think it was an architecture mismatch, I was compiling 64bit while the precompiled libs were 32bit. SO then I moved on to building from source and managed to do so by following these instructions:

    http://stackoverflow.com/questions/1...ld-gdal-in-x64

Similar Threads

  1. Environment of a QProcess
    By osiris81 in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2011, 11:53
  2. Configuring QT Creator environment
    By Asperamanca in forum Qt Tools
    Replies: 9
    Last Post: 22nd October 2009, 10:38
  3. does qt 4.5.1 have the app environment like qpe?
    By alexcuiCN in forum Installation and Deployment
    Replies: 0
    Last Post: 6th May 2009, 11:21
  4. Qt development environment?
    By klx in forum Newbie
    Replies: 3
    Last Post: 21st March 2008, 13:51
  5. how to set up Qt4 + KDevelop environment
    By mattie in forum Installation and Deployment
    Replies: 4
    Last Post: 20th March 2006, 14:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.