Skip to content

Conversation

@orlitzky
Copy link

@orlitzky orlitzky commented May 7, 2025

Attempting to build iODBC on a musl system, I hit a few "missing function" errors that turned out to be quick fixes. Two were missing includes, and one required a feature test macro to enable strdup().

orlitzky added 3 commits May 6, 2025 23:05
Without this the build can fail on musl:

  connect.c: In function '_iodbcdm_pool_set_retry_wait':
  connect.c:489:25: error: implicit declaration of function 'time'
  [-Wimplicit-function-declaration]
  489 |   pdbc->cp_retry_wait = time(NULL) + retry_wait;
      |                         ^~~~

Presumably glibc includes time.h incidentally via some other header.
Without this, the build can fail on musl:

  info.c: In function 'SQLDrivers_Internal':
  ../include/iodbc.h:117:34: error: implicit declaration of function
  'strcasecmp'; did you mean 'wcscasecmp'?
  [-Wimplicit-function-declaration]
  117 | #define STRCASEEQ(a, b) (strcasecmp((char*)(a), (char*)(b)) == 0)
      |                          ^~~~~~~~~~

Presumably glibc includes strings.h incidentally via some other
header.
Without this, the build can fail on musl:

  SQLGetInstalledDrivers.c: In function 'SQLGetInstalledDrivers_Internal':
  ../include/iodbc.h:117:34: error: implicit declaration of function
  'strdup'; did you mean 'strcmp'? [-Wimplicit-function-declaration]
  117 | #define STRDUP(t)               (strdup((char*)(t)))
      |                                  ^~~~~~
#ifndef _POSIX_C_SOURCE
/* POSIX.1-2008 is required for strdup() */
#define _POSIX_C_SOURCE 200809L
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#else error out if _POSIX_C_SOURCE < 200809L?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already errors, that's how I noticed :)

It would be nice to show the error as early as possible, but there's a small risk of breaking things for people with other C libraries. Clearly it works on glibc without the define, otherwise everyone would have noticed. But does it work on glibc with some earlier constant defined? (I don't know). If it does, then turning that into an error would probably be bad, even though anyone defining _POSIX_C_SOURCE to something less than 2008 has asked for it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant an earlier/more explicit error.

I'm on the side of 'fail fast', so I would welcome such 'breakage', but I know not everyone agrees

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants