簡體   English   中英

函數fseeko的隱式聲明

[英]Implicit declaration of function fseeko

我正在嘗試將fseeko函數與GCC編譯器結合使用,以處理C中大於4GiB的文件。現在,一切正常,我能夠處理超過4GiB的文件,但GCC一直在抱怨fseeko函數是隱式聲明的。 這是生成此消息的源代碼的最小工作示例:

#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

#include "MemoryAllocator.h"

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>

typedef struct BlockReader {
    char* fileName;
    // Total filesize of the file with name fileName in bytes.
    unsigned long long fileSize;
    // Size of one block in bytes.
    unsigned int blockSize;
    // Defines which block was last read.
    unsigned int block;
    // Defines the total amount of blocks
    unsigned int blocks;
} BlockReader;

unsigned char* blockreader_read_raw_block(BlockReader* reader, long startPos, unsigned int length, size_t* readLength) {
    FILE* file = fopen(reader->fileName, "rb");

    unsigned char* buffer = (unsigned char*) mem_alloc(sizeof(unsigned char) * (length + 1));

    FSEEK(file, startPos, 0);
    fclose(file);

    // Terminate buffer
    buffer[length] = '\0';
    return buffer;
}

我在任何地方都找不到要解決此警告的標頭。 GCC給出的確切警告是:

src/BlockReader.c: In function ‘blockreader_read_block’:
src/BlockReader.c:80:2: warning: implicit declaration of function ‘fseeko’ [-Wimplicit-function-declaration]
  FSEEK(file, reader->blockSize * reader->block, 0);

如果您使用-std選項(例如-std=c99-std=c11 ,則這些選項要求完全符合標准C的環境,默認情況下不公開POSIX接口(將它們暴露為不符合標准,因為它們是在為應用程序保留的名稱空間中)。 您需要將_POSIX_C_SOURCE_XOPEN_SOURCE定義為適當的值才能獲取它們。 -D_POSIX_C_SOURCE=200808L在命令行上,或者

#define _POSIX_C_SOURCE 200808L

在您的源文件中添加任何標題之前,將是這樣做的方法。

另外,雖然這不是您的直接問題,但請注意__USE_LARGEFILE64_LARGEFILE_SOURCE_LARGEFILE64_SOURCE都是不正確的。 要獲得64位off_t ,唯一需要做的就是在命令行上添加-D_FILE_OFFSET_BITS=64或在包含任何頭文件之前在源文件中#define _FILE_OFFSET_BITS 64

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM