[gdal-dev] When use std::string OGRPoint::exportToWkt(), get a LNK2019 error on Windows

zs s cmulershen at gmail.com
Mon May 18 01:19:10 PDT 2020


Hi,

I am a newbie in c ++ and gdal.
I used the following command to compile gdal3.1.0 on windows successfully:

nmake -f makefile.vc MSVC_VER=1910 WIN64=1 GDAL_HOME=path\to\gdal_home
PROJ_INCLUDE=-IC:\OSGeo4W\include PROJ_LIBRARY=C:\OSGeo4W\lib\proj.lib
SQLITE_INC=-Ipath\to\sqlite\include
SQLITE_LIB=path\to\sqlite\lib\libsqlite3.lib devinstall

But when I use std::string OGRPoint::exportToWkt() function, and compiled,
get a LNK2019 error like that:

error LNK2019: unresolved external symbol "private: static int __cdecl
OGRWktOptions::getDefaultPrecision(void)"
(?getDefaultPrecision at OGRWktOptions@@CAHXZ)´╝îreferenced in function "public:
__cdecl OGRWktOptions::OGRWktOptions(void)" (??0OGRWktOptions@@QEAA at XZ)

my code:

#include <iostream>

#include <ogrsf_frmts.h>
#include <ogr_geometry.h>

int main()
{
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

GDALDataset *dataset;
dataset = (GDALDataset *)GDALOpenEx("D:\\Point.shp", GDAL_OF_VECTOR,
nullptr, nullptr, nullptr);

if (dataset == nullptr)
{
std::cerr << "Open failed.\n";
exit(1);
}

OGRLayer *layer = dataset->GetLayer(0);

OGRFeature *feature;
layer->ResetReading();
while ((feature = layer->GetNextFeature()) != nullptr)
{

OGRGeometry *geom = feature->GetGeometryRef();

if (geom != nullptr)
{
const std::string wkt = geom->toPoint()->exportToWkt();

// std::cout << "GEOM: " << wkt << std::endl;
}
}

OGRFeature::DestroyFeature(feature);
GDALClose(dataset);

return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)

project(gdal-sample VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(GDAL REQUIRED)

add_executable(sample sample.cpp)

target_include_directories(sample PRIVATE ${GDAL_INCLUDE_DIR})

target_link_libraries(sample PRIVATE ${GDAL_LIBRARIES})

Am I doing something wrong?

thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200518/9ab048e6/attachment.html>


More information about the gdal-dev mailing list