简体   繁体   中英

warning: implicit declaration of function 'fsync' is invalid in C99

For some reason when I compile my code the compiler does not find the prototypes for fsync and truncate. I get this:

cc -c -Wall -Wno-overflow  -pedantic -std=c99 -I/Users/matt/Programming/BitEagle_Projects/cbitcoin/include -I/usr/local/ssl/include -I/opt/local/include -O3 -arch i386 -arch x86_64 -D_POSIX_SOURCE -fPIC dependencies/storage/CBBlockChainStorage.c -o build/CBBlockChainStorage.o
dependencies/storage/CBBlockChainStorage.c:154:6: warning: implicit declaration of function 'fsync'
      is invalid in C99 [-Wimplicit-function-declaration]
                if(fsync(indexAppend)){
                   ^
dependencies/storage/CBBlockChainStorage.c:649:6: warning: implicit declaration of function
      'truncate' is invalid in C99 [-Wimplicit-function-declaration]
        if (truncate(filename, CBArrayToInt32(data, 0))) {
            ^

What do I have to do to remove these warnings? I am including unistd.h. This is on OSX using clang:

$ cc --version
Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

Thank you.

If you are using -std=c99 , the system headers will attempt to provide a declaration/macro namespace compatible with the C standard, which does not include any of the additional functions from POSIX or other standard or nonstandard extensions. You need to define the appropriate feature test macros to get them. For example, put -D_POSIX_C_SOURCE=200809L on the command line or define it in your source files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM