openv / vcontrold

:fire: vcontrold Daemon for control and logging of Viessmann® type heating devices
https://github.com/openv/openv/wiki
GNU General Public License v3.0
103 stars 58 forks source link

compile errors on Mac OSX 10.15 #62

Closed hmueller01 closed 4 years ago

hmueller01 commented 4 years ago

When I try to compile vcontrold (current master), I get

[ 14%] Building C object CMakeFiles/vclient.dir/src/socket.c.o
/Users/hmueller/src/raspberry/vcontrold/src/socket.c:78:5: warning: implicit declaration of function 'asprintf' is invalid in C99 [-Wimplicit-function-declaration]
    asprintf(&port, "%d", tcpport);
    ^
/Users/hmueller/src/raspberry/vcontrold/src/socket.c:135:24: error: use of undeclared identifier 'NI_MAXHOST'
    char clienthost   [NI_MAXHOST];
                       ^
/Users/hmueller/src/raspberry/vcontrold/src/socket.c:136:24: error: use of undeclared identifier 'NI_MAXSERV'
    char clientservice[NI_MAXSERV];
                       ^
1 warning and 2 errors generated.

I use OSX Catalina with XCode. cmake from brew. cmake outputs

(hmueller@mbp2)~/src/raspberry/vcontrold/build> cmake -DVSIM=ON -DMANPAGES=OFF -DCMAKE_INSTALLATION_PREFIX=/usr/local ..
-- The C compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found LibXml2: /usr/lib/libxml2.dylib (found version "2.9.4") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALLATION_PREFIX

-- Build files have been written to: /Users/hmueller/src/raspberry/vcontrold/build

Looking into /usr/include/netdb.h I see

#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define NI_MAXHOST  1025
#define NI_MAXSERV  32
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

So it looks like _POSIX_C_SOURCE is defined and _DARWIN_C_SOURCE is not.

If I add set (CMAKE_C_FLAGS "-D_DARWIN_C_SOURCE ${CMAKE_C_FLAGS}") into CMakeLists.txt this error is gone. But this might not be correct for all platforms.

hmueller01 commented 4 years ago

Fixed with #72.