Search code examples
c++cmakeanacondagdalproj

How does one build GDAL 3.7.2 binaries


I'm trying to build the GDAL DLL and .lib files, so GDAL can be used for linker and includes in an other C++ project. We're needing to upgrade from GDAL 2.0.2 to 3.7.2.

Has anyone built GDAL from source before?

What did I try:

  1. Download GDAL: https://github.com/OSGeo/gdal/releases/tag/v3.7.2
  2. Unzip it to one folder
  3. Run the CMake GUI. How I got it: https://cmake.org/download/
  4. Using the GUI's "Where is the source code" field, set CMake to the directory you unzipped GDAL to. Note the below field that tells where the binaries are built. "target" in my case.
  5. Install Anaconda.
  6. In the "Anaconda Prompt", conda install -c conda-forge proj conda install -c anaconda swig
  7. Set the "PROJ_DIR" variable to the location in the pkgs folder in anaconda's install location. attempt at setting PROJ_DIR
  8. Hit "Configure" in the CMake GUI. Note the version of Visual Studio that it is intending for. CMake shows the VS version
  9. Hit "Generate".
  10. In the (in my case) "target" folder of your GDAL location there should now be a Visual Studio solution. Open it up in the aforementioned version of VS. Build the solution.

The build should fail with an error about being unable to find a "lib.obj". File paths have been hidden.

LNK1104 cannot open file '...\anaconda3\pkgs\proj-8.2.1-h5ed7ab8_0\Library\lib.obj' gdal "...\gdal-3.7.2\target\LINK"

lib.obj does not exist at that location. I have no idea what's supposed to create it. I don't know why the "conda install" command did not place the lib file there.

I also noticed that in the variables list (the big window in the middle of the GUI), for the PROJ_DIR variable, I've got "PROJ_DIR-NOTFOUND" after I manually set it to the above 'anaconda3\pkgs' directory. It changes to "PROJ_DIR-NOTFOUND" during the configure process.

What I was expecting: The build to succeed.


Solution

  • GDAL 3.7.2 is available in the conda-forge repository. Why not simply run

    conda install -c conda-forge gdal