GDAL Not Linking

别说谁变了你拦得住时间么 提交于 2021-02-16 20:11:13

问题


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*)'

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})

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?


回答1:


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.




回答2:


Thanks @MikeKinghan! I had been pulling my hair out for couple of days! Your answer clicked right away. For those who want to have no headache with the libraries, just use MSYS2 (msys2.org). Then using pacman in the msys2 command prompt, get the MingW (pacman -S mingw-w64-x86_64-gcc) and GDAL (pacman -S mingw-w64-x86_64-gdal).



来源:https://stackoverflow.com/questions/46842468/gdal-not-linking

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!