PDA

View Full Version : Add a DLL to Qt Creator's run environment



Phlucious
27th June 2012, 01:33
This is a pretty simple question that I imagine has a very simple answer.

I built a GDAL (http://www.gdal.org/) 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.

ChrisW67
27th June 2012, 05:02
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

Phlucious
27th June 2012, 17:45
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.

ChrisW67
27th June 2012, 23:24
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.

ip
28th August 2013, 06:01
hi...I am pretty new to GDAL library. Can you help me understand how do i build GDAL lib with Qt.

quimnuss
16th July 2015, 20:53
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:


moc_gpspublisher.obj:-1: error: LNK2001: unresolved external symbol "public: virtual __cdecl GDALMajorObject::~GDALMajorObject(void)" (??1GDALMajorObject@@UEAA@XZ)

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:

[...]

159 9E 00005F4C ??1GDALMajorObject@@UAE@XZ
[...]

which demangled is:
public: virtual __thiscall GDALMajorObject::~GDALMajorObject(void)

SO I noticed the difference __thiscall and __cdecl. The rellevant part of the code that defines what goes before each function is:


#ifndef CPL_DLL
#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
# define CPL_DLL __declspec(dllexport)
#else
# define CPL_DLL
#endif
#endif

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.


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)

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!

quimnuss
17th July 2015, 09:02
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/16526181/cant-build-gdal-in-x64