linux c之关于 Value too large for defined data type的解决

//#define _FILE_OFFSET_BITS 64
#include 
#include 
#include 

//stat file >2G
//Error calling stat: Value too large for defined data type
//http://stackoverflow.com/questions/13893580/calling-stat-from-sys-stat-h-faills-with-value-too-large-for-defined-data-typ
int main(int argc, const char *argv[])
{
    struct stat st;
#ifdef _FILE_OFFSET_BITS
    printf("_FILE_OFFSET_BITS=%d\n",_FILE_OFFSET_BITS);
#endif
    if (stat(argv[1], &st) != 0)
    {
        perror("Error calling stat");
    }
    printf("stat ok\n");

    return 0;
}

当stat file >2G 在linux会出现

Error calling stat: Value too large for defined data type
解决方法是:

#define _FILE_OFFSET_BITS 64
#include 
qt pro配置

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.c

#http://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value
# gcc -D_FILE_OFFSET_BITS=64
DEFINES += "_FILE_OFFSET_BITS=64"


include(deployment.pri)
qtcAddDeployment()




你可能感兴趣的:(linux_c)