maxmind / libmaxminddb

C library for the MaxMind DB file format
https://maxmind.github.io/libmaxminddb/
Apache License 2.0
912 stars 239 forks source link

Compiler constant PACKAGE_VERSION missing under Linux #280

Closed ocgltd closed 3 years ago

ocgltd commented 3 years ago

Compiling maxminddb.c under linux fails on line 1862 due to missing PACKAGE_VERSION constant.
This constant is defined in maxminddb.h line 31, but, it's wrapped in a condition for _WIN32. So in Linux this constant is undefined.

I moved the define outside the condition block and compiling proceeds. Seems like an easy fix. (But configure will likely remove that)

horgh commented 3 years ago

How are you building it? The regular build process will define it.

ocgltd commented 3 years ago

I followed the instruction on the code page of github:

$ ./configure
$ make
$ make check
$ sudo make install

It configured and installed everything, and the version const was present (inside a win32 conditional), but was not placed outside that conditional.

I hate to think it's just me :)

horgh commented 3 years ago

Oh, you are wanting to use PACKAGE_VERSION from your application? There's MMDB_lib_version(). I'm not sure whether we'd want to be defining PACKAGE_VERSION directly. The Windows case may be an oversight.

ocgltd commented 3 years ago

No - just trying to compile maxminddb.c , line 1862 references the PACKAGE_VERSION constant. Here's an excerpt from maxminddb.c

const char *MMDB_lib_version(void) { return PACKAGE_VERSION; }

Notice that the MMDB_lib_version functions makes use of the constant!

horgh commented 3 years ago

I see. Clearly I'm confused about what's going wrong :-). Can you paste your output? The build instructions for example that you pasted above should complete without error, as should using the resulting library.

horgh commented 3 years ago

Output with some context and such that is.

horgh commented 3 years ago

FWIW, as part of the build process, it'll be put in a config.h.

ocgltd commented 3 years ago

Everything installed without error, but the resulting header file is not usable under Linux. See for yourself, this is the section of the maxminddb.h file:

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
/* libmaxminddb package version from configure */
#define PACKAGE_VERSION "1.6.0"

typedef ADDRESS_FAMILY sa_family_t;

#if defined(_MSC_VER)
/* MSVC doesn't define signed size_t, copy it from configure */
#define ssize_t SSIZE_T

/* MSVC doesn't support restricted pointers */
#define restrict
#endif
#else
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif

So....the PACKAGE_VERSION constant is not defined under Linux. I understand what SHOULD happen, but it didn't happen. I'm not sure I can help beyond this, I have fixed it by moving the define outside the conditional

oschwald commented 3 years ago

This doesn't seem to be a bug. PACKAGE_VERSION should not be defined under Linux. It should also not be defined under Windows, but it is there for historical reasons; we will likely correct this in the future.

As Will mentioned, you should use MMDB_lib_version to get the version.