用 vcpkg 安装 gdal后,自己再编译filegdb插件, release版本没问题, debug版执行 GDALAllRegister() 就崩溃。
没办法,把vcpkg下载好的gdal源码拷贝出来,修改好 nmake.opt, 用nmmake自己编译~~~
源码位置: E:\tools\windows\vcpkg\vcpkg-2022.08.15\buildtrees\gdal\src\v3.5.1-2bdd297034
修改位置:
cmd进到源码根目录下,执行命令:
debug版:
nmake /f makefile.vc WIN64=YES DEBUG=1
release版:
nmake /f makefile.vc WIN64=YES
安装命令:
debug版:
nmake /f makefile.vc install
nmake /f makefile.vc devinstall
release版:
nmake /f makefile.vc
nmake /f makefile.vc devinstall
头文件可以直接用vcpkg安装的gdal的头文件, 库文件用自己编译的。 这样就不需要安装了
附上测试代码:
void testDriver(){
cout << " >>>>>>> go <<<<<<<" << endl;
GDALAllRegister();
cout << "GDALAllRegister ok" << endl;
const char *pszDriverName = "FileGDB";
CPLSetConfigOption( "GDAL_FILENAME_IS_UTF8", "NO" );
CPLSetConfigOption( "SHAPE_ENCODING", "CP936" );
GDALDriver *poGdbDriver = GetGDALDriverManager()->GetDriverByName(pszDriverName);
if (poGdbDriver == nullptr)
{
cout << "load driver failed" << endl;
return ;
}
cout << poGdbDriver << endl;
}
注: 为什么要拷贝vcpkg的源码,因为它已经做好了很多设置,只需要把自己额外的支持修改好就行了~~