tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
338 stars 97 forks source link

macOS build error: implicit declaration of function 'mkdtemp' is invalid in C99 #179

Closed autoantwort closed 3 years ago

autoantwort commented 3 years ago

When I try to build the project I get the following error:

[6/19] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -I/Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/x64-osx-dbg/src -fPIC -g -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -MD -MT CMakeFiles/matio.dir/src/mat.c.o -MF CMakeFiles/matio.dir/src/mat.c.o.d -o CMakeFiles/matio.dir/src/mat.c.o -c /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/src/e20f937598-58771d06f1.clean/src/mat.c
FAILED: CMakeFiles/matio.dir/src/mat.c.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -I/Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/x64-osx-dbg/src -fPIC -g -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -MD -MT CMakeFiles/matio.dir/src/mat.c.o -MF CMakeFiles/matio.dir/src/mat.c.o.d -o CMakeFiles/matio.dir/src/mat.c.o -c /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/src/e20f937598-58771d06f1.clean/src/mat.c
/Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/src/e20f937598-58771d06f1.clean/src/mat.c:89:18: error: implicit declaration of function 'mkdtemp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( NULL != mkdtemp(dir_buf) ) {
                 ^
/Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/matio/src/e20f937598-58771d06f1.clean/src/mat.c:89:15: warning: comparison between pointer and integer ('void *' and 'int') [-Wpointer-integer-compare]
    if ( NULL != mkdtemp(dir_buf) ) {
         ~~~~ ^  ~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
tbeu commented 3 years ago

Our CI builds matio on macOS but could not repoduce so far. Check the builds .17, .18 and .19 from https://app.travis-ci.com/github/tbeu/matio/builds/233045460.

Can you please check and confirm if efcd262855931460ebe80d4042b0e8f9c46c1d13 works in your environment.

Otherwise you can also get the binaries from Conan center.

autoantwort commented 3 years ago

Can you please check and confirm if efcd262 works in your environment.

Yeah that works 👍

tbeu commented 3 years ago

Fixed in master.

seanm commented 2 years ago

I think only the #include <unistd.h> was necessary. Just tried on my own build and removing #define _DARWIN_C_SOURCE does not break the build. The man page also does not say anything about needing a special define...

tbeu commented 2 years ago

Thanks for confirmation @seanm . Since _DARWIN_C_SOURCE does not hurt, I am reluctant to remove it again.

seanm commented 2 years ago

I'm not convinced it "does not hurt". Who knows what all the various included headers may do differently based on that being defined or not.

Also, looking at the FreeBSD and OpenBSD man pages, it might be best to #include <unistd.h> unconditionally. I could try to building master on them...

tbeu commented 2 years ago

_DARWIN_C_SOURCE is removed again by 34b1708.

@autoantwort Please confirm if still relevant for you. Thanks.

autoantwort commented 2 years ago

Still builds without errors.

seanm commented 2 years ago

Thanks!

I also tried FreeBSD and indeed it builds.