CMake引用Gdal

首先将编译好的gdal根目录注册到GDAL_DIR环境变量;并将${GDAL_DIR}/bin路径添加到系统path环境变量。

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(untitled1 LANGUAGES CXX)
add_executable(${PROJECT_NAME} main.cpp)

find_package( GDAL )
if(GDAL_FOUND)
    target_include_directories(${PROJECT_NAME} PRIVATE ${GDAL_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} ${GDAL_LIBRARY})
else(GDAL_FOUND)
    message( FATAL_ERROR "GDAL library not found" )
endif(GDAL_FOUND)

main.cpp

#include <stdio.h>
#include <gdal.h>

int main()
{
    const char* info = GDALVersionInfo("");
    printf("%s\n",info);
    return 0;
}

运行程序测试

 

posted @ 2021-03-31 12:56  松山居士  阅读(1919)  评论(0编辑  收藏  举报