CMake引用Gdal

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

cmakelist.txt

cmake_minimum_required(VERSION 3.5)

project(untitled1 LANGUAGES C)
add_executable(untitled1 main.c)

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

main.c

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

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

运行程序测试

CMake引用Gdal

 

上一篇:[VirtualBox] 显示模式


下一篇:VirtualBox在win10下安装一个国产深度os桌面系统的操作教程