Search code examples
curlmingwmingw-w64

Undefined reference to difftime64 when compiling static cURL with mingw64


I am trying to build a static executable for Windows embedding cURL:

  • MinGW-64 (x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z link)
  • Pre-compiled CURL packages from official website

The experience is quite straight-forward until the link phase where I have one remaining linker error.

third-party\lib\static\curl-7.73\lib\libssh2.a(session.o):(.text+0x367): undefined reference to `__imp__difftime64'

This function seems to come from the C standard library and is originally named difftime (<time.h>). For a reason I don't understand, the symbol seems to have been renamed from difftime to difftime64 when session.o was built.

I tried to copy a function definition directly in my source code:

/* static __inline__ I don't want inline anymore                */
/*                   I want to export this function for libssh2 */
double _difftime64( __time64_t __t1, __time64_t __t0 )
{
  return (double)((long double)(__t1) - (long double)(__t0));
}

// I also tried to name the function "difftime64", "_difftime64" and "__difftime64"
// With the same results

Unfortunately, this naive approach does not work and the linker error remain. Is there a way to rename to session.o import name with bintutils or a way to tell the linker that difftime64 is actually difftime?


Solution

  • You can get a standalone build of the latest version of MinGW-64 from winlibs.com.