4

I'm using libconfig inside a project and thought convenient to compile it with the rest of the code using my nested CMakeLists.txt scripts. Here are the contents of the directory where the libconfig source files are located:

[config] -> ls
CMakeLists.txt  libconfig.c       libconfig.h++  scanctx.h  strbuf.c
grammar.c       libconfigcpp.c++  libconfig.hh   scanner.c  strbuf.h
grammar.h       libconfigcpp.cc   parsectx.h     scanner.h  wincompat.h
grammar.y       libconfig.h       scanctx.c      scanner.l

Here are the contents of CMakeLists.txt:

set(config_source_files
    grammar.c
    libconfig.c
    libconfigcpp.c++
    scanctx.c
    scanner.c
    strbuf.c
)
add_library(config ${config_source_files})

I get a few warnings when I compile on my Linux (Fedora 20) machine. I get an error when I compile on my OSX (Yosemite) machine:

/Users/m4urice/myproject/src/utilities/config/libconfig.c:90:3: error: 
    use of undeclared identifier 'locale_t'
locale_t loc = newlocale(LC_NUMERIC_MASK, "C", NULL);

Does anyone have an idea of what this could be due to?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
M4urice
  • 571
  • 6
  • 15
  • 3
    1. DO NOT IGNORE WARNINGS. 2. Also, you can use `FILE(GLOB config_source_files ${CMAKE_CURRENT_SOURCE_DIR}/*.c)`. Is `locale.h` included in `libconfig.c`? – Iharob Al Asimi Sep 17 '15 at 10:45

1 Answers1

1

It would seem that libconfig.c is not seeing:

#include <xlocale.h>

which is required for OS X builds, but not for Linux (see fuller explanation below).

There is probably some configuration option or build switch that you are missing that would normally cause this header to be included on OS X builds. I suggest you take a look at libconfig.c and perhaps the other libconfig headers to see if there's an #ifdef which controls the inclusion of <xlocale.h> (try grepping for "xlocale.h"). Also check any accompanying README, makefile, or other documentation.


On Linux the required header for newlocale and locale_t is:
#include <locale.h>

but OS X requires:

#include <xlocale.h>

When in doubt, see the man page:

NEWLOCALE(3) BSD Library Functions Manual NEWLOCALE(3)

NAME newlocale -- Create a new locale

SYNOPSIS #include <xlocale.h>

locale_t
newlocale(int mask, const char * locale, locale_t base);
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Well, libconfig.c is a source file of the library. It does not sound right to add includes into their code. I think it's likely that the problem is somewhere else. – davak Sep 18 '15 at 08:11
  • @davak: it depends whether this library has ever been tested on Mac OS X, but you're right, maybe the OP is missing some configuration option or build parameter that would include the right header for OS X - I'll update the answer to cover this. – Paul R Sep 18 '15 at 08:13
  • Well, I've been using libconfig for years, never under OS X though. But the authors claim that they support OS X and I do not see a reason not to believe them. I just took a look at the source and in order to have xlocale.h included, HAVE_XLOCALE_H must be defined. – davak Sep 18 '15 at 08:22
  • Thanks for looking at the source to confirm - I guess the OP needs to check the documentation and/or accompanying makefiles to see what he's missing. – Paul R Sep 18 '15 at 08:25
  • 1
    Thanks a lot for these anwsers. I finally came up with a workaround which allowed me to use the autotools scripts shipped with libconfig and compile without warning on both systems. Now the warnings when compiling on Linux are gone as well; so I guess I was missing a few of compiler flags indeed. – M4urice Sep 18 '15 at 10:07