GDAL未链接 [英] GDAL Not Linking

查看:44
本文介绍了GDAL未链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的程序在Windows上运行.它取决于GDAL,这是一个用于加载GIS数据的库.它可以在Linux和macOS上正常编译和链接.我将CMake与MinGW结合使用,并且遇到了如下错误:

I'm trying to get my program running on Windows. It depends on GDAL, a library for loading GIS data. It compiles and links fine on both Linux and macOS. I'm using CMake with MinGW and I'm running into linking errors like this:

undefined reference to `GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long, long, GDALRasterIOExtraArg*)'
CMakeFiles\Routes.dir/objects.a(elevation.cpp.obj): In function `ZN13ElevationData9calcStatsEv':
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:138: undefined reference to `GDALDataset::GetRasterXSize()'
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:139: undefined reference to `GDALDataset::GetRasterYSize()'
CMakeFiles\Routes.dir/objects.a(elevation.cpp.obj): In function `ZN13ElevationData17createOpenCLImageEv':
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:206: undefined reference to `GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long, long, GDALRasterIOExtraArg*)'

我使用VS2017编译了GDAL,并且已验证它已安装在我在CMake文件中指定的位置.这是CMakeLists.txt的相关部分:

I compiled GDAL with VS2017 and I've verified that it is installed where I am specifying in my CMake File. Here is the relevant portions of the CMakeLists.txt:

IF (WIN32)

  message(STATUS "Compiling for Windows")
  set(GDAL_LIBRARY "C:/warmerda/bld/lib/gdal_i.lib")
  set(GDAL_INCLUDE_DIR "C:/warmerda/bld/include/")

  find_package(OpenCL REQUIRED)
  include_directories(${OpenCL_INCLUDE_DIRS})

ELSE()

...

message(STATUS ${GDAL_LIBRARY})
target_link_libraries(Routes ${GDAL_LIBRARY} ${OpenCL_LIBRARIES})

我几乎从来没有在Windows上进行过开发,所以有点卡住了.我已经尝试过针对dll进行链接,但无济于事.有什么想法吗?

I almost never do development on Windows so I'm kind of stuck. I've tried linking against the dll as well with no avail. Any ideas?

推荐答案

显然,您正在尝试将用VC ++编译的库与对象链接您正在使用GCC(MinGW)进行编译的文件.那不行GCC和VC ++具有不同且不兼容的 ABI ,尤其是不同的名称修改协议.因此,MinGW在目标代码中发出的错误函数名称将与您的VC ++编译库导出的任何内容都不匹配.您将需要用MinGW构建GDAL库.

Apparently you're attempting to link a library you compiled with VC++ with object files that you're compiling with GCC (MinGW). That doesn't work. GCC and VC++ have different and incompatible ABIs, and in particular different name mangling protocols. Hence the mangled function names emitted by MinGW in your object code will not match any exported by your VC++ compiled library. You will need to build the GDAL library with MinGW.

这篇关于GDAL未链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆