cmacoscmakelibconfig

libconfig: error when compiling using CMake


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?


Solution

  • 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);