I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.

Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.

After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:


However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".

#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>

Where should I further investigate?

1 Answer 1


Based on the ouput from vcpkg when installing any new package:

Computing installation plan...
The following packages will be built and installed:
Starting package 1/1: zlib:x64-windows
Building package zlib[core]:x64-windows...
-- Downloading http://www.zlib.net/zlib-1.2.11.tar.gz...
-- Extracting source D:/Dev/vcpkg/downloads/zlib1211.tar.gz
-- Applying patch cmake_dont_build_more_than_needed.patch
-- Using source at D:/Dev/vcpkg/buildtrees/zlib/src/1.2.11-deec42f53b
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Installing: D:/Dev/vcpkg/packages/zlib_x64-windows/share/zlib/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package zlib[core]:x64-windows... done
Installing package zlib[core]:x64-windows...
Installing package zlib[core]:x64-windows... done
Elapsed time for package zlib:x64-windows: 28.35 s

Total elapsed time: 28.35 s

The package zlib is compatible with built-in CMake targets:

    find_package(ZLIB REQUIRED)
    target_link_libraries(main PRIVATE ZLIB::ZLIB)

So you will have to add

find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)

to your CMakeLists.txt file for your project.

  • Sadly, when installing gdal with vcpkg no output like this will be shown. In my CMakeLists.txt-file i have the lines: find_library(GDAL gdal) and target_link_libraries(main gdal)
    – Nestroy
    Apr 7, 2020 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.