From c39585dc93b3ac1262ff8c9bb448b03f19c4ca5a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 5 Aug 2020 15:21:25 +0100 Subject: [PATCH] ECC-1141: Compile error on MinGW: undefined reference to 'realpath' --- CMakeLists.txt | 1 + eccodes_config.h.in | 10 ++++++---- src/grib_context.c | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d6b2c4c8..de667e7d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ check_symbol_exists( fseeko "stdio.h" ECCODES_HAVE_FSEEKO ) check_symbol_exists( posix_memalign "stdlib.h" ECCODES_HAVE_POSIX_MEMALIGN ) check_symbol_exists( fmemopen "stdio.h" ECCODES_HAVE_FMEMOPEN ) check_symbol_exists( funopen "stdio.h" ECCODES_HAVE_FUNOPEN ) +check_symbol_exists( realpath "stdlib.h" ECCODES_HAVE_REALPATH ) check_c_source_compiles( " typedef int foo_t; diff --git a/eccodes_config.h.in b/eccodes_config.h.in index 6cdae518c..6c00bc7bb 100644 --- a/eccodes_config.h.in +++ b/eccodes_config.h.in @@ -50,6 +50,7 @@ #cmakedefine ECCODES_HAVE_POSIX_MEMALIGN #cmakedefine ECCODES_HAVE_FMEMOPEN #cmakedefine ECCODES_HAVE_FUNOPEN +#cmakedefine ECCODES_HAVE_REALPATH #if defined(EC_HAVE_ASSERT_H) || defined(ECCODES_HAVE_ASSERT_H) #define HAVE_ASSERT_H 1 @@ -64,15 +65,15 @@ #endif #if defined(EC_HAVE_SYS_STAT_H) || defined(ECCODES_HAVE_SYS_STAT_H) -#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_STAT_H 1 #endif #if defined(EC_HAVE_FCNTL_H) || defined(ECCODES_HAVE_FCNTL_H) -#define HAVE_FCNTL_H 1 +#define HAVE_FCNTL_H 1 #endif #if defined(EC_HAVE_UNISTD_H) || defined(ECCODES_HAVE_UNISTD_H) -#define HAVE_UNISTD_H 1 +#define HAVE_UNISTD_H 1 #endif #if defined(EC_HAVE_FSEEKO) || defined(ECCODES_HAVE_FSEEKO) @@ -80,9 +81,10 @@ #endif #if defined(EC_HAVE_POSIX_MEMALIGN) || defined(ECCODES_HAVE_POSIX_MEMALIGN) -#define POSIX_MEMALIGN 1 +#define POSIX_MEMALIGN 1 #endif + /* other */ #define IEEE_BE @IEEE_BE@ diff --git a/src/grib_context.c b/src/grib_context.c index 350ad0a1a..5feeb6f66 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -607,9 +607,7 @@ grib_context* grib_context_new(grib_context* parent) static char* resolve_path(grib_context* c, char* path) { char* result = NULL; -#ifdef ECCODES_ON_WINDOWS - result = grib_context_strdup(c, path); -#else +#if defined(ECCODES_HAVE_REALPATH) char resolved[ECC_PATH_MAXLEN + 1]; if (!realpath(path, resolved)) { result = grib_context_strdup(c, path); /* Failed to resolve. Use original path */ @@ -617,7 +615,10 @@ static char* resolve_path(grib_context* c, char* path) else { result = grib_context_strdup(c, resolved); } +#else + result = grib_context_strdup(c, path); #endif + return result; }